Enumeration For/in

Source: Internet
Author: User

The for/in loop iterates through all the properties that can be enumerated in the object, including its own and inherited properties. The built-in methods of object inheritance cannot be enumerated, and the property methods that are added to the object's own or inherited classes in code are enumerable, but the built-in properties of the object can be enumerated, not necessarily, For example, we can try math's built-in random property (not enumerable) and window's built-in Name property (enumerable).

I. The following summarizes some of the tool functions that enumerate object properties:

1. If O and P have the same name attribute, p overrides o

function Extend (o,p) {    for in  p) {        ifcontinue;   Masking Enumerable inherited properties        O[prop] = P[prop];    }     return o;}

2. If O and P have the same name attribute, p does not affect the O property

function Merge (o,p) {    for in  p) {        ifcontinue;   Masking an enumerable inherited property        ifcontinue;   property with the same name skipped        O[prop] = P[prop];    }     return o;}

3. If the O attribute does not have the same name attribute in P, delete the attribute in O

function Restrict (o,p) {    for (var . o) {        ifin  P) Delete O[prop];    }     return o;}

4. Delete the property with the same name in P in O

function Subtract (o,p) {    for (var in p) {        delete o[prop];    }     return o;}

Enumeration For/in

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.