![]() |
Javascript reflective reference
If i am right than every object is under window.
i wrote this code for(i in window) { document.write(i+"<br/>"); } it returns me every defined object but there is some object which is created by constructor and they are not returned if("WebSocket" in window) how can i get these what else could be missing |
some folks say you can't.
here is a wise-guy workaround, but it's more of a joke than a real tool. still, it might find a couple of surprises for you. window.dump? hehe or it may hang your browser. grab a sandwich check back later. yes, it's a brute-force object detector. i'd never seen one before. this is just a proof of concept. i want a scalable distributed version. Code:
var mystery=window; //"hello world" false [1,2,3] after about 30 seconds, it had found this when run on this page using firebug: Code:
{i wrote this just this weekend. this one is 7 chars, and the code got away from me, so it's a little sloppy. the 4 chars was fast and stable, but limited. real answer: i think firebug is easier. |
The for..in statement will never process anything flagged as not enumerable. This includes many of the predevined properties and methods in the built in objects (such as window).
The latest version of JavaScript provides more direct access to the se types of settings so that you can now create your own properties and methods that will have that flag set and so be skipped over by for..in |
| All times are GMT +1. The time now is 06:03 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.