$.extend(des,src,src2);
api文档这么写的,但是当src,src不是obj是一个字符串的时候,结果是把字符串每个字符单独拆出来放到des上
var ext = {name:111} $.extend(ext,{age:999}) console.log(ext)
==>Object {name: 111, age: 999}
当src不是对象的时候
1 var ext = {name:111} 2 $.extend(ext,"这可是什么情况啊!!!","我去!")
===>Object {0: "我", 1: "去", 2: "!", 3: "什", 4: "么", 5: "情", 6: "况", 7: "啊", 8: "!", 9: "!", 10: "!", name: 111}
测试到这,突然想到extend的顺序,貌似树上说是右侧的会覆盖左侧对象相同的属性值,看遍历的结果貌似不是这样,而是先从右侧遍历,如果左侧有相同的属性则不
读取的它的值。
1 var ext = {name:111} 2 $.extend(ext,{aa:11,tt:33},{aa:22},"我去!") 3 console.log(ext)
==>Object {0: "我", 1: "去", 2: "!", name: 111, aa: 22, tt: 33}