Well, to my knowledge, the only way to create non-enumerable property in
ES5 is to use `Object.defineProperty` (or any other method allowing to
set attributes — `Object.defineProperties`, `Object.create`, etc.)
And anyone using `defineProperty` (or similar methods) is likely
creating a property intentionally, contrary to unnoticed undeclared
assignment.
Or any third party script, GA for example ;-)
Using strict mode (once implemented; currently only in Besen, but
Mozilla is making a significant progress lately —
<
http://kangax.github.com/es5-compat-table/strict-mode/>) might be a
better solution to undeclared assignments, where they result in
ReferenceError.
Probably.
You can also look into my "detect global" bookmarklet
(
http://perfectionkills.com/detecting-global-variable-leaks/) or
Garrett's JScript RuntimeObject -based one
(
http://dhtmlkitchen.com/?category=/Browsers/&date=2010/04/11/&entry=D...)
Well done, but I prefer mine
haven't you tried it ? You should
load it as early as possible, and once installed it keeps monitoring
*fresh*new* globals creation in ~ real time. Really nice. BTW
Garrett's code is definitely too much IE-centric.
javascript
function () {
var saved= Object.getOwnPropertyNames(window);
(function globalsMonitor (curr, names) {
curr= Object.getOwnPropertyNames(window);
if (curr.length !== saved.length) {
names= [];
curr.forEach(function (v,i,o) {
if (saved.indexOf(v) < 0) {
names.push( v+ " ["+ typeof window[v]+ "] : "+ window[v]+ "\r");
}
});
alert(names.length+ " new globals :\r"+ names);
saved= curr;
}
setTimeout(globalsMonitor, 1e3);
})();
})();
After "installing" it, just create a new global and an alert should
popup in no more than a second. Currently it only works in Chromes and
Safaris.