jQuery.extend(target, object1[,objectN]);
jQuery.extend([deep], target, object1[,objectN]);
jQuery.extend(object);
deep:类型为布尔型,如果为true,则合并为递归(也称深复制),默认为false,表不支持传递此参数
target: 类型为对象,将接收新属性对象
object1:类型为对象,包含要合并的附加属性对象。
objectN:类型为对象,包含要合并的附加属性对象。
object: 要合并到jQuery命名空间对象。
var defaults = {
validate: false,
limit: 5,
name: "foo"
};
var options = {
validate: true,
name: "bar"
};
var settings = jQuery.extend({}, defaults, options);
var settings2 = jQuery.extend({ _name: "434" });
$("#log").append("defaults:" + JSON.stringify(defaults) + "</br>");
$("#log").append("options: " + JSON.stringify(options) + "</br>");
$("#log").append("settings: " + JSON.stringify(settings) + "</br>");
$("#log").append("typeof settings:" + (typeof settings) + "</br>");
$("#log").append("settings2: " + JSON.stringify(settings2) + "</br>");
$("#log").append("typeof settings2: " + (typeof settings2));
// defaults:{"validate":false,"limit":5,"name":"foo"}
// options: {"validate":true,"name":"bar"}
// settings: {"validate":true,"limit":5,"name":"bar"}
// typeof settings:object
// settings2: undefined
// typeof settings2: function
</script>