jQuery’s extend
method does a memberwise copy of one or more objects onto a target object and returns the altered target object.
For example, say I have an object that represents some default options, like this:
var defaultOptions = {
foo: "foo",
bar: "bar"
};
var options = {
foo: "hmm",
derp: "derp"
};
If I call $.extend({}, defaultOptions, options)
, I’ll get back this result:
{
foo: "hmm",
bar: "bar",
derp: "derp"
}
This is handy when you want to have default options in a private member, then pass in an options object that only overrides what you configure and leaves the rest of the defaults alone.