Re: function pointers vs direct calling in javascript



On Nov 21, 1:13 pm, Randy Webb <HikksNotAtH...@xxxxxxx> wrote:
Told ya you wouldn't believe me :)
I believe you. :-)

Is this so that it doesn't go out to search the
scope tree to look for 'tempVar2' or for some other reason?

That's a possibility, although it isn't in this case.
So you mean there are cases where this would be true? Any examples?

An detailed explanation with any relevant links would be greatly
appreciated.

Detailed explanation of the use of the var keyword? I am sure there is
one somewhere but I don't have a link to one. The simplest way to
remember it is that using var on a variable name in a function will
*never* alter a global variable. I always use it unless I explicitly
want to alter a global variable from within a function. The only other
time it can come into play is with inner functions and I never use them.
They give me too big a headache and I have never had a use for them.
Here is what I think of 'var', correct me if I am wrong.

'var' doesn't as such declare a variable. You don't need 'var' keyword
to *declare* variables or put them in the symbol tree in javascript.
It's just an indication to the scripting engine that 'please put this
variable in a scope which is local to this function. So saying:

var a = 10;
var a = 11;

doesn't actually create two variables or declare two variables but
refer to the same variable both the times which is 'a' which was
declared and defined using the statement 'a = 10'. Thus prepending the
variable name with 'var' separates it from the global namespace
(scope) (assuming we are not using 'with' in which case we would have
an additional scope).

Is this good enough?

Thanks and regards,
/~STS
.



Relevant Pages

  • Re: Dynamic variable names
    ... Note that var defines the scope of a variable. ... variable you initialize belongs to the scope where it has been ... But it has been added no assignment yet, ...
    (comp.lang.javascript)
  • Re: function pointers vs direct calling in javascript
    ... //lots of entries in tempVar here ... Detailed explanation of the use of the var keyword? ... to *declare* variables or put them in the symbol tree in javascript. ... variable in a scope which is local to this function. ...
    (comp.lang.javascript)
  • Re: function pointers vs direct calling in javascript
    ... scope tree to look for 'tempVar2' or for some other reason? ... Here is what I think of 'var', correct me if I am wrong. ... 'var' doesn't as such declare a variable. ... a property of the global object when the code executes. ...
    (comp.lang.javascript)
  • Re: Lets organize our Delphi code
    ... Well, no, I don't think a Delphi compiler capable of block scope variables should do it that way internally. ... The report was opened in the same day by Chris Pattinson. ... I don't think that would be slower at runtime (if no hidden nested procedures are generated by the compiler). ...
    (borland.public.delphi.non-technical)
  • Re: Default argument values for blocks
    ... >This one was proposed long ago as a way to declare a var whose scope is ... All sorts of things can work, ...
    (comp.lang.ruby)