JQ源码分析(2.0.3)---$.extend() $.fn.extend()

$.extend():作为扩展工具方法

$.extend({
aaa:function(){
alert(123);
},
bbb:function(){
alert(456);
}
})

$.aaa();
$.bbb();

 

$.fn.extend():作为jQ的实例方法

$.fn.extend({
aaa:function(){
alert(123);
},
bbb:function(){
alert(456);
}
})

$().aaa();
$().bbb();

深拷贝和浅拷贝

var a = {}
var b = {name:'hello'}
$.extend(a,b);
a.name = 'hi';
console.log(b.name);//hello
//浅拷贝
var a = {}
var b = {name:{age:'hello'}}
$.extend(a,b);
a.name.age = 'hi';
console.log(b.name.age);//hi
//深拷贝
var a = {}
var b = { name:{age:'hello'}}
$.extend(true,a,b);
a.name.age = 'hi';
console.log(b.name.age);//hello

var aa = {}

$.extend(a,{b:'123'})

 

posted @ 2017-12-14 22:49  码我滴码  阅读(95)  评论(0编辑  收藏  举报