jquery 插件开发 extjs中的extend用法小结

2020-05-23 06:23:39易采站长站整理

jQuery.extend( true,
{ name: “John”, location: { city: “Boston” } },
{ last: “Resig”, location: { state: “MA” } }
);
// 结果
// => { name: “John”, last: “Resig”,
// location: { city: “Boston”, state: “MA” } }
3) 如果是ext js的话,看下有什么不同

var start = {
id: 123,
count: 41,
desc: ‘this is information’,
title: ‘Base Object’,
tag: ‘uncategorized’,
values: [1,1,2,3,5,8,13]};
var more = { name: ‘Los Techies’, tag: ‘javascript’};
var extra = { count: 42, title: null, desc: undefined,
values: [1,3,6,10]};
var extended = Ext.apply(start, more, extra);console.log(JSON.stringify(extended));

输出
{ “id”: 123, “count”: 42, “title”: null, “tag”: “javascript”, “values”: [1,3,6,10], “name”: “Los Techies”}
可以看到,extjs中使用的是apply,而desc居然在合拼的结果中丢掉了,因为ext js认为undefind的东西不应该出现在合拼的结果中了,认为是擦除掉原来的值了,这个要注意