I have a project that I am working on where I am not able to use jQuery. Since using jQuery, I have become very acustomed to the way that parameters can be set in a function. It is very nice doing it the “jQuery” way, so that it does not matter the order, or even if you use all defaults like a normal function method would need.
So, my question is how would I turn like this:
function myFunction(param1, param2, param3, param4, param5) {
}
To a jQuery like method, without using jQuery:
function myFunction({
param1: 'test',
param2: 'test2'
});
Any help on this would be great!
I think you want to define a single options argument in your function, and extend it against a default values object:
Then if you call:
options.param1will be overriden within your function, andoptions.param2will remain with its default value “test2”.