From: Ry Nohryb on 9 Aug 2010 05:05 Keeping an eye on the count of global symbols might help you spot unintentionally undeclared vars that turn into globals. Now with Object.keys it seems to be as easy as: Object.keys(window).length --> 436 (function(){ k= 27; })(); Object.keys(window).length --> 437 -- Jorge.
From: Ry Nohryb on 9 Aug 2010 06:05 On Aug 9, 11:05 am, Ry Nohryb <jo...(a)jorgechamorro.com> wrote: > Keeping an eye on the count of global symbols might help you spot > unintentionally undeclared vars that turn into globals. Now with > Object.keys it seems to be as easy as: > > Object.keys(window).length > --> 436 > > (function(){ k= 27; })(); > > Object.keys(window).length > --> 437 Or is it better for any reason for the job at hand to use Object.getOwnPropertyNames(window).length ? -- Jorge.
From: Ry Nohryb on 9 Aug 2010 07:32 On Aug 9, 12:05 pm, Ry Nohryb <jo...(a)jorgechamorro.com> wrote: > On Aug 9, 11:05 am, Ry Nohryb <jo...(a)jorgechamorro.com> wrote: > > > Keeping an eye on the count of global symbols might help you spot > > unintentionally undeclared vars that turn into globals. Now with > > Object.keys it seems to be as easy as: > > > Object.keys(window).length > > --> 436 > > > (function(){ k= 27; })(); > > > Object.keys(window).length > > --> 437 > > Or is it better for any reason for the job at hand to use > Object.getOwnPropertyNames(window).length ? How about this one for monitoring globals during development ? (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); })(); })(); Whenever a new global is detected, an alert will pop up to tell us. -- Jorge.
From: Asen Bozhilov on 9 Aug 2010 08:38 Ry Nohryb wrote: > Keeping an eye on the count of global symbols might help you spot > unintentionally undeclared vars that turn into globals. Now with > Object.keys it seems to be as easy as: > > Object.keys(window).length > --> 436 > > (function(){ k= 27; })(); > > Object.keys(window).length > --> 437 Don't you use debugger for this case? For example I use `javascript.options.strict = true;` during development stage and if there are undeclared assignments I get message in console.
From: Ry Nohryb on 9 Aug 2010 08:54 On Aug 9, 2:38 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote: > Ry Nohryb wrote: > > Keeping an eye on the count of global symbols might help you spot > > unintentionally undeclared vars that turn into globals. Now with > > Object.keys it seems to be as easy as: > > > Object.keys(window).length > > --> 436 > > > (function(){ k= 27; })(); > > > Object.keys(window).length > > --> 437 > > Don't you use debugger for this case? For example I use > `javascript.options.strict = true;` during development stage and if > there are undeclared assignments I get message in console. My debuggars don't have that: > javascript --> ReferenceError: Can't find variable: javascript > javascript.options --> ReferenceError: Can't find variable: javascript ? And, what if what you're debugging is neither strict code nor strict- rules compliant ? -- Jorge.
|
Next
|
Last
Pages: 1 2 Prev: javascript is good Next: Stderr catch with Javascript to show progress of a running program? |