|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
How does firebug watch global variablesWhen debugging javascript with firebug, all global variables can be
watched in the "watch" window. The thing I'm wondering is how does firebug list these variables. I get the sources of firebug but cannot find where firebug does it. -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablesOn Oct 29, 9:10 pm, Yel <richardr...@...> wrote: > When debugging javascript with firebug, all global variables can be > watched in the "watch" window. > The thing I'm wondering is how does firebug list these variables. > I get the sources of firebug but cannot find where firebug does it. I guess I don't understand. Just use for-in loop over "window" properties? You must have something else in mind. jjb -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablesOn Oct 30, 12:44 pm, John J Barton <johnjbar...@...> wrote: > I guess I don't understand. Just use for-in loop over "window" > properties? > You must have something else in mind. > jjb Yeah, for-in loop over "window" does work in Firefox, although I cannot make sure if firebug really works in this way. BTW: for-in loop cannot list global variables in IE6/7/8 except they are declared like "window.gVar = xxx". I guess that's why IE Developer Toolbar cannot tell global variables or debug it. -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablesYel wrote:
> On Oct 30, 12:44 pm, John J Barton <johnjbar...@...> > wrote: > >> I guess I don't understand. Just use for-in loop over "window" >> properties? >> You must have something else in mind. >> jjb >> > > Yeah, for-in loop over "window" does work in Firefox, although I > cannot make sure > if firebug really works in this way. > BTW: for-in loop cannot list global variables in IE6/7/8 except they > are declared like > "window.gVar = xxx". I guess that's why IE Developer Toolbar cannot > tell global > variables or debug it. alert with 123: javascript:var xxx = 123;alert(window.xxx) But output of below function is browser's engine dependant: var xxx = 123 function test() { var out = document.getElementsByTagName('textarea')[0] for (var obj in window) { if (typeof(window[obj])!='function') out.value+='\nwindow.'+obj +' => ('+typeof(window[obj])+') '+ window[obj]; } } In FF it will show you quite a lot of stuff and your global variables. In Chrome you will get even more as some "null" variables will be shown (like window.on*). In IE you will get pretty much the same as in Chrome, but without global variables. And in Opera... Well I was kinda shocked, because the output was "window.opera => (object) [object Opera]" :-)). Then I noticed some of stuff linked to window object in Opera doesn't have toString methods so you'll have use something like: {out.value+='\nwindow.'+obj +' => ('+typeof(window[obj])+') '+ window[obj];}catch (e){} And then it will work in Opera too and it will show you global vars. And as you said before setting window.xxx rather then var xxx will make it work for IE too. Still watching the variable xxx in IE's dev tool _is_ possible in both situations. The only drawback is that you won't see your watch if you're not debugging (simply switching to debugging won't work - you'll have to break on some point). Regards, Nux. -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablesOn Oct 29, 10:53 pm, Yel <richardr...@...> wrote: > On Oct 30, 12:44 pm, John J Barton <johnjbar...@...> > wrote: > > > I guess I don't understand. Just use for-in loop over "window" > > properties? > > You must have something else in mind. > > jjb > > Yeah, for-in loop over "window" does work in Firefox, although I > cannot make sure > if firebug really works in this way. Firebug's dom.js (the code that supports the Watch side panel) applies getMembers() to what ever object is the current selection for the panel. The default selection is this.context.getGlobalScope() and tabContext.js shows us that the global scope for a context in Firebug is "this.window", another words the window object for the current Firebug context. (Chromebug supports non-window scopes). And getMembers uses for-in loop to get the properties of its current selected object. jjb -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablescontinue with this topic.
I wrote some scripts to try to loop all objects in the browser (say, firefox), and made it below : {{{ <script type="text/javascript"> function Hashtable() { this._hash = new Object(); this.add = function(key,value){ if(typeof(key)!= "undefined"){ if(this.contains(key)==false){ this._hash[key] = (typeof(value)=="undefined"? null:value); return true; } else { return false; } } else { return false; } } this.remove = function(key){delete this._hash[key];} this.count = function(){var i=0;for(var k in this._hash){i++;} return i;} this.items = function(key){return this._hash[key];} this.contains = function(key){return typeof(this._hash[key])!= "undefined";} this.clear = function(){for(var k in this._hash){delete this._hash [k];}} this.toString = function(){ var str = []; for (var i in this._hash){ str.push(i.toString()); } return str.join("<br />"); } } var vars = new Hashtable(); function takesnapshot() { list = function(obj) { if(obj.toString() == 'vars') return; // exclude vars self. vars.add(obj.toString(), obj.toString()); for(var p in obj) list(p); } list(window); // now, vars is a snapshot of window. } setTimeout(takesnapshot, 10); setTimeout(function(){ alert("vars len = " + vars.count()); document.body.innerHTML = vars.toString(); }, 2000); </script> }}} However, it didn't output what I wanted. Moreover, the output differed between IE and firefox (or Chrome etc.) Is it caused by the single threading implementations of javascript? Thanks for any idea. -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
|
|
Re: How does firebug watch global variablesOn Nov 23, 6:25 pm, Yel <richardr...@...> wrote: > continue with this topic. > > I wrote some scripts to try to loop all objects in the browser (say, > firefox), and made it below : > > {{{ > <script type="text/javascript"> > > function Hashtable() ... > var vars = new Hashtable(); Just a suggestion, read up some on Javascript, say for example, Doug Crockford's book "Javascript the Good Parts". That code looks like Java... > function takesnapshot() > { > list = function(obj) > { > if(obj.toString() == 'vars') return; // exclude vars self. > vars.add(obj.toString(), obj.toString()); ? I guess you meant to add p, obj[p].toString()? > for(var p in obj) list(p); You are passing the field name in to list. > } ... > However, it didn't output what I wanted. Moreover, the output differed > between IE and firefox (or Chrome etc.) Sure it will be different. Some the same some different. > Is it caused by the single threading implementations of javascript? Huh? No. jjb -- You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to firebug@.... To unsubscribe from this group, send email to firebug+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/firebug?hl=en. |
| Free embeddable forum powered by Nabble | Forum Help |