Re: What do people use Venkman for?

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jsdebugger
Organization Liberty Development
Message-ID <[email protected]>

Robert North wrote:


> I think the debugger is working, but it does a first pass over the code, 
> creating global variables, and setting them to null.
> Then, it goes back and runs the code *properly*.

Well check the ECMAScript specification, it is *proper* execution to 
first processs variable declarations to create variables. You can find 
details about that in the section "12.2 Variable statement" of the 
ECMAScript edition 3 specification where it says
   "Variables are created when the execution scope is entered. A Block 
does not define a new execution
scope. Only Program and FunctionDeclaration produce a new scope. 
Variables are initialised to undefined
when created. A variable with an Initialiser is assigned the value of 
its AssignmentExpression when the
VariableStatement is executed, not when the variable is created."

So what you see in Venkman is simply the script engine creating the 
variables first and initializing them to undefined, there is nothing 
wrong with that.

This is different from languages like Java where variables have block 
scope. In JavaScript/ECMAScript you can even access a variable before 
its declaration e.g.

if (x == 3) {
   print(x);
}
var x;

as the execution of that program first looks for variable declarations 
and creates variables. You could say that in ECMAScript variable 
declarations are "hoisted" to the beginning of the execution scope.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.