Extending Objects in jQuery


Welcome to my journey of  extending objects in JavaScript frameworks; let’s explore jQuery! Extending an object in jQuery is simple, there are just a few rules you need to understand. Extension works from left to right and you’re allowed to pass as many objects to the function as you want. Whatever is passed to the $.extend argument last wins.

For instance:



Output:



Again, remember that the last one in wins. It is also worth noting that anything extended with an explicit `undefined` will keep its original value. If you want to override a value with a “falsy” value, use `null`, `false` or anything else that makes sense in your case.

Arrays are always overwritten by the last object passed in.  The objects inside them are at mercy of their parents. It doesn’t matter if they are values or objects, the last object passed in, gets the last call.

For more information: http://api.jquery.com/jQuery.extend/

Extending Objects with JavaScript