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, 5:16 pm, Nic Hubbard <nnhubb...@gmail.com> wrote: > 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 am, fredrik <carl.fredrik.bonan...@gmail.com> wrote: > > > > > 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: 'hello world'}); > > > On Jun 24, 8:07 am, 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 to set defaults and pass in changes to those defaults > > > through as a param. Is this possible, or do I have to make this a > > > jQuery function like $.myfunction() ? > > > > I am trying: > > > > function test(defaults) > > > { > > > var defaults = { > > > test: '' > > > }; > > > > alert(defaults.test); > > > > } > > > > test({test: 'It works!'}); > > > > The above does not seem to work, and replace the default with that was > > > passed in the function. What am I doing wrong here?