ドキュメント

Utilities/jQuery.extend

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Utilities

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)Boolean
If set, the merge becomes recursive (i.e. deep copy).
targetObject
The object to extend.
object1Object
The object that will be merged into the first.
objectN (Optional)Object
More objects to merge into the first.
Examples:

Merge settings and options, modifying settings.

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

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

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

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

NameType