jquery中$.extend()的参数及用法学习

关于$.extend(boolean,{},p1,p2)中 boolean的用法:

 

//例1 $.extend(boolean,{},p1,p2)
var result=$.extend(false, {}, 
{ last: "Resig", location: {state: "MA",county:"China"} },{ name: "John", location: {job:"web",city: "Boston",county:"USA"} } ); 

console.log(result);
console.log(result.location);
/* 
boolean为true
输出:
{last: "Resig", location: Object, name: "John"}

输出:
{state: "MA", county: "USA", job: "web", city: "Boston"}

boolean为false
输出:
{last: "Resig", location: Object, name: "John"}

输出:
{job: "web", city: "Boston", county: "USA"}

*/
//由上面例子可知,当boolean值是true是,是根据p1、p2对象中key的进行取并集(p2与p1中的key值相同替换 不同添加),都是p2替换p1,当boolean值是false时  由于嵌套子对象location里的不同 所以不取并集 取交集;p2的location替换p1的location

 

posted on 2016-02-21 11:24  源人  阅读(565)  评论(0编辑  收藏  举报

导航