jQuery.extend扩展函数简单用法
jQuery.extend扩展函数简单用法
静态扩展
$.extend({
test:function(){alert(‘this test!’)}
})
使用$.test()
重载合并
var people1 = {
apple: 0,
banana: { weight: 52, price: 100 }
};
var people2 = {
banana: { price: 200 },
age: 100
};
//将people2中的内容追加,覆盖到people1,破坏people1原有结构
$.extend(people1,people2);
//people1的内容变为:{apple:0,banana{price:200},age:100}
//下面方式是合并到新的变量,从而不破坏people1
var newPeople=$.extend({},people1,people2);
//people1的内容变为:{apple:0,banana{price:200},age:100}
//深度合并
$.extend(true,people1,people2);
//people1的内容变为:{apple:0,banana{weight: 52,price:200},age:100}