javascript definition guide(javascript权威指南)第六章 Example 6-2里的例子有一个小错误
/**
* Copy the enumerable properties of p to o, and return o.
* If o and p have a property by the same name, o's property is overwritten.
* This funcdtion does not handle getters and setters or copy attributes.
*/
function extend(o, p){
for (prop in p)
o[prop] = p[prop];
return o
}
/**
* Return a new object that holds the properties of both o and p.
* If o and p have properties by the same name, the values from o are used
*/
function union(o, p) {
return extend(extend({}, o), p);
}
正确的函数应该是:
function union(o, p) {
return extend(p, extend({}, o));
}