jquery extend方法
1. extend(dest,src1,src2,src3...);
demo:
var result=$.extend({},{name:"Tom",age:21},{name:"Jerry",sex:"Boy"})
合并后的结果
result={name:"Jerry",age:21,sex:"Boy"}
2.省略dest参数
$.fn.extend(src) 该方法将src合并到jquery的实例对象中去,如:
$.fn.extend({ hello:function(){alert('hello');} });
常用:在jquery中扩展命名空间 并扩展命名空间:
扩展一个命名空间 $.extend({net:{}});
向之前扩展的命名空间添加函数 $.extend($.net,{ hello:function(){alert('hello');} })
3.深度拷贝
extend(boolean,dest,src1,src2,src3...)
例子:
var result=$.extend( true, {}, { name: "John", location: {city: "Boston",county:"USA"} }, { last: "Resig", location: {state: "MA",county:"China"} } );
结果:
result={name:"John",last:"Resig", location:{city:"Boston",state:"MA",county:"China"}}
如果第一个参数是false结果是:
result={name:"John",last:"Resig",location:{state:"MA",county:"China"}}
如果没有第一个方法,都是浅拷贝;
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">