anything that the docs doesn't explain properly?

it pretty much "combines" two objects, saving the result in the object
specified as the first parameter... in Mike's awesome article, he has
"default" values but if the user passes in options, the .extend()
method overwrites the defaults with what the user passed in

if the second parameter of the .extend() has a same key as the first
parameter, the second parameter "wins"

here's a quick example:

http://jsbin.com/itihe3/edit (code)
http://jsbin.com/itihe3 (view)

so in the first extend: $.extend(obj1, obj2);
- obj1 and obj2 don't share any key names, so the result is all the
keys names, "obj1" is now 6 items long

the second: $.extend(obj1, obj3);
- obj3's "key1" value overwrote what obj1 had  (and again, obj1 is now
storing this merging)

the third: $.extend(obj1, obj3);
- obj3's "foo2" value overwrote what obj2 had (and now obj2 has the
merged values)

in the plugin article, and in many many plugins, you'll see that they
take the result and assign it to another variable to keep the combined
set inside the closure (I'm pretty sure, heh)

that help?



On Dec 30, 12:47 pm, "T.J. Simmons" <theimmortal...@gmail.com> wrote:
> Hi all,
>
> Got a quick question. I'm writing my second plugin following Mike
> Alsup's pattern (http://www.learningjquery.com/2007/10/a-plugin-
> development-pattern) and the only part that I have yet to wrap my head
> around is using $.extend().. I understand what it does, sorta, but not
> the why. I've read the documentation for $.extend and it doesn't seem
> to make much sense with the way it's used within that walkthrough, at
> least not to me.
>
> Is anyone able to put it in a more understandable way, other than what
> the documentation has?
>
> Thanks,
> T.J.

Reply via email to