views:

91

answers:

2

Is there any way I can view the variables used in a javascript function without trawling through the code?

Using javascript on a server so cant really install an app to debug, is there a javascript function i can use in some way?

A: 

Hi,

Well to list them you could try something like: for (var avar in this) console.log(avar)

Anyway, doesnt your server side JavaScript engine allow you to place breakpoint and see the vars in real time?

HTH

Romansky
The properties of `this` are not the same as the variables in scope, and in fact inside a function call where `this` is not the global object will be completely unrelated.
Tim Down
WTF with the downvote??If the this refers to the global scope window then it WILL list the relevant variables. I would down vote you if I could (not enough rep)
Romansky
I downvoted your answer because it is incorrect, for the reasons I gave. Your comment "If the this refers to the global scope window then it WILL list the relevant variables." isn't quite true: `this` wouldn't contain the list of arguments passed into the function, for example. And as I pointed out, if `this` isn't the global object then its properties will have nothing to do with the variables in scope. And why would you downvote my answer?
Tim Down
well for one you are behaving like a prick (I was trying to help), other then that I would agree some clarification would be helpful on top of my answer, but I hardly see a reason to downvote me.My answer is better then nothing. And I would downvote you thanks to your shitty attitude.
Romansky
I don't doubt you were trying to help. I downvoted your answer, I didn't downvote *you*; try not to take it so personally. And if you improve your answer I will remove my downvote: there is something useful in what you say, but it needs a lot of qualification and as it stands is vague and misleading.
Tim Down
+1  A: 

Not unless the JavaScript implementation you're using has some extension that provides such a feature (browsers don't). JavaScript resolves identifiers inside a function using the scope chain; there's no single object that contains all the variables in scope, and the objects in the scope chain are inaccessible from code.

Tim Down