tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

jQuery.extend( deep, target, ...)

jQuery.extend[deep], target, object1, [objectN] )

Extend one object with one or more others, returning the modified object.
If no target is specified, the JQuery namespace itself is extended. This can be useful for plugin authors wishing to add new methods to JQuery.

Keep in mind that the target object will be modified, and will be returned from extend().

If a boolean true is specified as the first argument, JQuery performs a deep copy, recursively copying any objects it finds. Otherwise, the copy will share structure with the original object(s).

Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over.

Arguments

deep (Optional)
If set, the merge becomes recursive (i.e. deep copy).
target
The object to extend.
object1
The object that will be merged into the first.
objectN (Optional)
More objects to merge into the first.

Examples

Example 1

Merge settings and options, modifying settings.
var settings = { validate: false, limit: 5, name: "foo" };
var options = { validate: true, name: "bar" };
jQuery.extend(settings, options);

Result:

settings == { validate: true, limit: 5, name: "bar" }

Example 2

Merge defaults and options, without modifying the defaults.
var empty = {}
var defaults = { validate: false, limit: 5, name: "foo" };
var options = { validate: true, name: "bar" };
var settings = $.extend(empty, defaults, options);

Result:

settings == { validate: true, limit: 5, name: "bar" }
empty == { validate: true, limit: 5, name: "bar" }
Was this information helpful?
   

Comments