There is a small error in the example in Chapter 6 of the Javascript definition Guide (JavaScript authoritative guide), 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 ({}, O ), p );}
If the Union function is implemented here, If O and P have the same attribute, the o attribute will still be overwritten by the attribute in P.
The correct function should be:
Function Union (O, P) {return extend (p, extend ({}, O ));}