Saturday 15 May 2010

javascript - Get all user defined window properties? -


Is there any way to detect all user defined window properties and variables (global variable) in JavaScript? <<> console.log (window) tried but the list is endless.

You will need to work for yourself, read in all the qualities, you can do at the first possible time. . From that point on, you can compare the property list with your static list.

  var globalProps = []; Read GlobalPopes () {globalProps = object .getOwnPropertyNames (window); } Function findNewEntries () {var current PropList = Object.getOwnPropertyNames (window); Return currentPropList.filter (search duplicate); Function Search Duplicate (Proponym) {Return global page. Index (Propaneme) === -1; }}   

So, now we may be like

  // init readGlobalProps (); // Store the current property on the global object   

and later

  window.foobar = 42; FindNewEntries (); // gives an array of new properties, in this case ['FOOBAR']   

Of course, the warning is here, that you can only "freeze" global property list At that time, where your script is able to call it as soon as possible.

No comments:

Post a Comment