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);

http://docs.jquery.com/Utilities/jQuery.extend

On Jun 24, 3: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?

Reply via email to