I am not sure if I understand the question, but you should be able
to create a breakpoint in the scope where the var is defined
break on it and use the Watch side panel window.
Honza
On May 9, 2:38 pm, AlphaPage <alphap...@gmail.com> wrote:
> Hello,
> Is there a way to watch and display a private var in the watch tree ?
> It would be great to be able to do that.
> Thanks in advance for your help.
For now, I'm only able to watch 'public' var, but I'd like to watch
private var.
To bypass the problem, I need to add 'this' before my var to make it
'public' which is very boring.
Honza, your answer works if my object is used 3 or 4 times max, but
my object is often inside a for loop, so it will break to often.
That's why I hope 'private' or 'nested' var could be displayed in
watch tree without depending on internal breakpoint.
On May 9, 6:08 pm, AlphaPage <alphap...@gmail.com> wrote:
> For now, I'm only able to watch 'public' var, but I'd like to watch
> private var.
> To bypass the problem, I need to add 'this' before my var to make it
> 'public' which is very boring.
You can watch only variables that are available in the current scope
(e.g. the place where the breakpoint is).
> Honza, your answer works if my object is used 3 or 4 times max, but
> my object is often inside a for loop, so it will break to often.
> That's why I hope 'private' or 'nested' var could be displayed in
> watch tree without depending on internal breakpoint.
I know I can bypass the problem, but it would be great to get private
var or return value from function more quickly.
I mean for example:
MyModule2 = function (strInput) {
if (false === (this instanceof MyModule2)) {
return new MyModule2();
}
var str = strInput;
this.getStr = function () {
return str;
}
this.customStr = "custom str";
};
document.getElementById("Button2").onclick = function () {
var module2 = new MyModule2("input");
console.log(module2.getStr());
debugger;
}
In the quick watch panel (very nice feature), this.customStr is
displaying "custom str" because it is public :perfect.
It's impossible to spy the str var because it is private. If I add a
watch, str var is undefined which is wrong because str="input".
So to get the str var, I use my public Getter function getStr(). The
quick watch panel shows getStr with a link to jump to the code (no
problem), but it would be perfect if another row helps to watch the
data returned when asked. I need to right click getStr, select "add
watch" then reformat the watch from "module2.getStr" to
"module2.getStr()" and finally get the data "input".
I think being able to spy private var and spy returned value from
function when needed would be a great feature to ease javascript
debugging.
But this is just my opinion.
Den torsdagen den 10:e maj 2012 kl. 12:04:59 UTC+2 skrev AlphaPage:
> I need to right click getStr, select "add > watch" then reformat the watch from "module2.getStr" to > "module2.getStr()" and finally get the data "input".
So, for functions with .length === 0, a right-click option "watch return value" would be good?
FireClosure <https://github.com/simonlindholm/fireclosure> would also give you exactly what's needed here - you could just add a watch for "module2.%str". Would you mind trying it out and giving me some feedback? (It's somewhat fragile, and works only with >= Firefox Aurora.)
On May 10, 11:12 pm, Simon Lindholm <simon.lindhol...@gmail.com>
wrote:
> So, for functions with .length === 0, a right-click option "watch return
> value" would be good?
I'd just like a button near the function to get the return value of
the function, but if nothing returned, display 'undefined'.
But an even better tool would display 2 toggle buttons next to the
'class' ie module2:
- the 'private' or closure scope button will loop through all the
module2.% var to display all the private var in the scope (and hide
undefined var for example)
- the return value from function button will loop through all the
module2 function to display all the return values in the scope (and
doesn't display data when no value is returned from the function)
> FireClosure <https://github.com/simonlindholm/fireclosure> would also give
> you exactly what's needed here - you could just add a watch for
> "module2.%str". Would you mind trying it out and giving me some feedback?
> (It's somewhat fragile, and works only with >= Firefox Aurora.)
You learned me something with module2.%str to watch 'private' var.
Thank you.
I tried FireClosure and get a closure scope displayed in the quick
watch panel, but no str var from my breakpoint: maybe I am using it
the wrong way ! But seems promising if it is made to give me what I am
trying to achieve.
Den fredagen den 11:e maj 2012 kl. 12:02:36 UTC+2 skrev AlphaPage:
> I'd just like a button near the function to get the return value of > the function, but if nothing returned, display 'undefined'.
Where in the UI? (Just draw a picture in Paint or something.) This and the "display all return values" doesn't seem to work with stateful functions, and ones taking >0 arguments. Also, for watches in particular, adding the function as a watch seems to be conceptually wrong in the first place; you really want the return value.
> But an even better tool would display 2 toggle buttons next to the > 'class' ie module2: > - the 'private' or closure scope button will loop through all the > module2.% var to display all the private var in the scope (and hide > undefined var for example)
FireClosure should add one such thing in DOM views (though it's hacky and might be removed later, I dunno), where else should it go? (Again, mspaint'd screenshot.)
> FireClosure <https://github.com/simonlindholm/fireclosure> would also > give > > you exactly what's needed here - you could just add a watch for > > "module2.%str". Would you mind trying it out and giving me some > feedback? > > (It's somewhat fragile, and works only with >= Firefox Aurora.) > You learned me something with module2.%str to watch 'private' var.
Wellll.. it's not standard and just a syntax I made up for FireClosure. But I hope that works alright.
I tried FireClosure and get a closure scope displayed in the quick
> watch panel, but no str var from my breakpoint: maybe I am using it > the wrong way !
Hm, I don't really understand what you're saying. Screenshot of what you expect to appear?
> Simon, you are right and to get the return value from a function inside > the dom is stupid. I apologize, the command bar is made to do so and my > request was only working on the particular case when the function simulates > a property. > But for private var, I attach 2 pictures to show if my request is suitable: > - Toggle bitmap : a button (the purple square) could be toggled to display > all the private var in the class or module when the user wants (%str = > "input" would be displayed: % will tell a private var, or a different color > formatting) > - Menu bitmap : an other way would be to be able to select "Show private > var" from the menu, but maybe it will slow down the dom processing.
Finally, I discovered that FireClosure is doing the job, but only inside the Dom panel. That's why I wasn't able to find it inside the quick watch panel. It would be a fantastic add-on if I could watch in both places and be able to choose when I want the scoped var tree menu to be auto expanded or not (for now, the scoped var node is always collapsed).
But I must admit that FireClosure shows me private var as you tell me Simon. Thank you.
> Finally, I discovered that FireClosure is doing the job, but only inside
> the Dom panel. That's why I wasn't able to find it inside the quick watch
> panel.
>> Finally, I discovered that FireClosure is doing the job, but only inside
>> the Dom panel. That's why I wasn't able to find it inside the quick watch
>> panel.
It's not entirely clear how a flat view of closures would work; what levels
of the closure chain are included? What if only relatively global
properties are available (could be from optimizations etc.)? Also the
purple square looks a bit weird. Having '%member' in purple looks cool,
admittedly.