What RobG said. Standard way to do that:
function test(options){
var defaults = { test: '' };
options = jQuery.extend(defaults, options);
alert(options.test);
};
test({test: 'It works!'});
You can also simply skip the defaults var and use jQuery.extend
({ test: '' }, options);
Not really sure what you are after. But I think you need to make an
new instance of test first:
var test = function (defaults){
this.defaults = defaults || this.defaults;
alert(this.defaults.test);
}
test.prototype = {
defaults : { test : 'nothing' }
};
new test();
new test({test:
How does jQuery do it for plugins? I was wanting to be able to use
callbacks as well in the object.
What is happening what a plugin uses: var options = $.extend(defaults,
options);
Somehow, that is getting the object to pass through as the function
params.
Any help on this?
On Jun 24, 12:09
If you want a really simple example:
function test(o) {
var defaults = {
test: ''
};
for(var k in o){
defaults[k] = o[k];
}
alert(defaults.test);
}
test({test: 'It works!'});
(nb. also assigns new properties to 'defaults')
On Jun 24, 4:07 pm, Nic Hubbard nnhubb...@gmail.com wrote:
I have used an object in the past as a function argument, but this was
for a plugin that I wrote. Using it in the architecture of a plugin
it worked.
BUT, this time, I just want to write a normal function, but still use
an object
5 matches
Mail list logo