Javascript definition Guide (JavaScript authoritative guide) Chapter 6 a small error in example 6-2

Source: Internet
Author: User

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 ));}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.