Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2012, 04:54 AM   PM User | #1
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,454
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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"
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 12-07-2012 at 04:57 AM..
rnd me is offline   Reply With Quote
Reply

Bookmarks

Tags
defineproperty, ecma5, getownpropertynames, oop

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:13 PM.


Advertisement
Log in to turn off these ads.