$.extend(obj1,obj2...,objN)小结 扩展obj1属性,有返回值,返回第一个被扩展后的对象
<script>
var obj1 = {
name:'liu',
age:'24'
}
var obj2 = {
name:'jinyu',
sex:'man'
}
$.extend(obj1,obj2); //直接将obj2合并到obj1中 扩展obj1
//obj1 { name:'jinyu' , age:'24' , sex:'man'} //obj1 的属性改变
</script>
var obj1 = {
name:'liu',
age:'24'
}
var obj2 = {
name:'jinyu',
sex:'man'
}
$.extend(obj1,obj2); //直接将obj2合并到obj1中 扩展obj1
//obj1 { name:'jinyu' , age:'24' , sex:'man'} //obj1 的属性改变
</script>
<script>
var obj1 = {
name:'liu',
age:'24'
}
var obj2 = {
name:'jinyu',
sex:'man'
}
var obj3 = $.extend({},obj1,obj2); //直接合并obj1,obj2到 空{}中,返回合并结果,赋给obj3
//obj3 { name:'jinyu' , age:'24' , sex:'man'} //返回合并结果并赋给obj3
//obj1 { name:'liu' , age:'24' } //obj1 的属性不变
</script>
var obj1 = {
name:'liu',
age:'24'
}
var obj2 = {
name:'jinyu',
sex:'man'
}
var obj3 = $.extend({},obj1,obj2); //直接合并obj1,obj2到 空{}中,返回合并结果,赋给obj3
//obj3 { name:'jinyu' , age:'24' , sex:'man'} //返回合并结果并赋给obj3
//obj1 { name:'liu' , age:'24' } //obj1 的属性不变
</script>