javascript - Is there a way of obtaining all library objects within an instance of JS? -
is there method in can iterate through objects exist within instance of javascript, regardless of javascript engine being used? i'm not interested in iterating through dom of web page. want know if there way can iterate through standard library objects (array, math, date, etc.) additional libraries may specific various browsers.
no... , yes. window
object global object in browser. contains native members of global scope, plus functions , properties provided dom.
native objects math, array , date non-enumerable members of global object, means can't iterate on them using for...in
loop. covers "no" part — there's no way of obtaining these objects through iteration in many browsers.
however, ecmascript 5th edition implementations (ie 9, chrome 7, firefox 4) can use object.getownpropertynames()
array of property names specific object. instance,
console.log(object.getownpropertnames(window));
will give list of members of global window
object, including math, array, date, etc.
Comments
Post a Comment