From: RobG on 9 Aug 2010 22:38 On Aug 9, 7:05 pm, 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. Where "now" means at some time in the future when implemented in your browser of choice. It may be useful to note that Object.kyes is an ES 5 feature and can hardly be called ubiquitous at present. > Now with > Object.keys it seems to be as easy as: > > Object.keys(window).length > --> 436 It may also be worth noting that the window object is not necessarily the global object. Wouldn't it be better to use something like: var globalObj = this; function countGlobals() { var keys; if (globalObj && typeof Object.keys == 'function') { keys = Object.keys(globalObj); return keys && keys.length; } } -- Rob
From: Garrett Smith on 10 Aug 2010 00:38 On 2010-08-09 05:54 AM, Ry Nohryb wrote: > On Aug 9, 2:38 pm, Asen Bozhilov<asen.bozhi...(a)gmail.com> wrote: >> Ry Nohryb wrote: [..] >> 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: > Firefox/Seamonkey: about:config -- Garrett
From: Ry Nohryb on 10 Aug 2010 03:35 On Aug 10, 4:38 am, RobG <rg...(a)iinet.net.au> wrote: > On Aug 9, 7:05 pm, 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. > > Where "now" means at some time in the future when implemented in your > browser of choice. > > It may be useful to note that Object.keys is an ES 5 feature and can > hardly be called ubiquitous at present. You're right, currently (2010-08-10) it's only in Chrome and Safari, it seems. > > Now with > > Object.keys it seems to be as easy as: > > > Object.keys(window).length > > --> 436 > > It may also be worth noting that the window object is not necessarily > the global object. Wouldn't it be better to use something like: > > var globalObj = this; > > function countGlobals() { > var keys; > if (globalObj && typeof Object.keys == 'function') { > keys = Object.keys(globalObj); > return keys && keys.length; > } > } Yes, very good, thanks :-) -- Jorge.
From: Ry Nohryb on 10 Aug 2010 03:44 On Aug 10, 6:38 am, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: > On 2010-08-09 05:54 AM, Ry Nohryb wrote: > > > My debuggars don't have that: > > Firefox/Seamonkey: > about:config Ah, that, yes, thanks, now I recall it. But I develop mostly in webkits (Safari/Chrome) and debug in the webInspector. -- Jorge.
From: RobG on 10 Aug 2010 09:36 Ry Nohryb wrote: > On Aug 10, 4:38 am, RobG <rg...(a)iinet.net.au> wrote: >> On Aug 9, 7:05 pm, 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. >> Where "now" means at some time in the future when implemented in your >> browser of choice. >> >> It may be useful to note that Object.keys is an ES 5 feature and can >> hardly be called ubiquitous at present. > > You're right, currently (2010-08-10) it's only in Chrome and Safari, > it seems. Thanks for the tip. Tried Firefox, no go. But Safari 5 is good. > >>> Now with >>> Object.keys it seems to be as easy as: >>> Object.keys(window).length >>> --> 436 >> It may also be worth noting that the window object is not necessarily >> the global object. Wouldn't it be better to use something like: >> >> var globalObj = this; >> >> function countGlobals() { >> var keys; >> if (globalObj && typeof Object.keys == 'function') { >> keys = Object.keys(globalObj); >> return keys && keys.length; >> } >> } > > Yes, very good, thanks :-) It's a bit tidier if the return is moved outside the if block. It was written in Firefox in a few moments, actually works (as far as I can tell) in Safari and returns undefined in Firefox and IE 6 as expected. -- Rob
First
|
Prev
|
Pages: 1 2 Prev: javascript is good Next: Stderr catch with Javascript to show progress of a running program? |