...

View Full Version : viewing non-iterable properties



rnd me
12-07-2012, 05:54 AM
the big three now support a way to iterate the new {enumerable:false} - style properties long-used by browser makers themselves.


Object.getOwnPropertyNames( anyObject );

a nicer way to access it is via a shortcut on Object, next to .keys():

Object.keys2=Object.getOwnPropertyNames;

Object.keys(window).length // 202
Object.keys2(window).length // 337


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




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:



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"




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,s ort,filter,forEach,some,every,map,indexOf,lastIndexOf,reduce,reduceRight"
//ie: "constructor,push,concat,join,pop,reverse,shift,slice,sort,splice,toLocaleString,toString,unshift,ind exOf,every,filter,forEach,lastIndexOf,map,reduce,reduceRight,some,length"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum