/*
* 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 function does not handle getters and setters or copy attributes.
*/
function extend(o, p) {
for(prop in p) { // For all props in p.
o[prop] = p[prop]; // Add the property to o.
}
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); }
我认为联盟,他的意思是“使用p的值”。权威指南(6ed)错误?
我在Chrome上做了测试。我错了吗?抱歉。当我学习时,我倾向于非常小心,特别是这是Javascript的第一本书,6ed最近。
变种O = {X:1}
变种P = {X:2}
功能扩展(邻,对){
for(prop in p) o[prop] = p[prop]; return o;
}
功能联盟(o,p){
return extend(extend({},o),p);
变种克=联盟(邻,对)
g.x
谢谢。
你是对的... – sje397
你可以在这里提交勘误表:http://oreilly.com/catalog/errata.csp?isbn=9780596805531 –