Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 Posts

    viewing non-iterable properties

    the big three now support a way to iterate the new {enumerable:false} - style properties long-used by browser makers themselves.

    Code:
    Object.getOwnPropertyNames( anyObject );
    a nicer way to access it is via a shortcut on Object, next to .keys():
    Code:
    Object.keys2=Object.getOwnPropertyNames;
    
    Object.keys(window).length // 202
    Object.keys2(window).length // 337

    for example, user-defined "hidden" props are actually available:


    Code:
    o={a:1};
    Object.defineProperty(o, "b", { value: 2, enumerable: false });
    
    Object.getOwnPropertyNames(o)+''; // ["a", "b"]
    Object.keys(o) // ["a"]
    o.toSource() // "({a:1})" (ff)
    o['b'] // 2


    also, now you can easily iterate Native Methods:

    Code:
    Object.getOwnPropertyNames(Number.prototype)+'';
    //ff: "constructor,toSource,toString,toLocaleString,valueOf,toFixed,toExponential,toPrecision"
    //ch: "constructor,toString,toLocaleString,valueOf,toFixed,toExponential,toPrecision"
    //ie: "constructor,toExponential,toFixed,toPrecision,toLocaleString,toString,valueOf"
    Code:
    Object.getOwnPropertyNames(Array.prototype)+'';
    //ff: "length,constructor,toSource,toString,toLocaleString,join,reverse,sort,push,pop,shift,unshift,splice,concat,slice,indexOf,lastIndexOf,forEach,map,reduce,reduceRight,filter,some,every,iterator"
    //ch: "length,constructor,toString,toLocaleString,join,pop,push,concat,reverse,shift,unshift,slice,splice,sort,filter,forEach,some,every,map,indexOf,lastIndexOf,reduce,reduceRight"
    //ie: "constructor,push,concat,join,pop,reverse,shift,slice,sort,splice,toLocaleString,toString,unshift,indexOf,every,filter,forEach,lastIndexOf,map,reduce,reduceRight,some,length"
    Last edited by rnd me; 12-07-2012 at 04:57 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •