Re: "x.constructor == Foo" vs "x instanceof Foo"



Thomas 'PointedEars' Lahn <PointedEars@xxxxxx> writes:

function a() { alert("First") }

function b() { a() };

function a() { alert("Second") }

b();

The second declaration for `a' overwrites the reference with one to another
Function object before b() is executed. ISTM you have just proved that
there is a closure :)

I expected that reply and have prepared the following, demonstrating
that the lookup of a() in b() is done via dynamic, not lexical scoping.

function a() { alert("first") }

function b() { a() }

c = { a: function() { alert("second") } };
a();

with (c) {
a();
}

every function that calls another function,
Not every function. It depends on where the other function was defined.

See code above. We're accessing a global property, not a lexical
variable. The fact that the variable is a function doesn't matter.

That seems contradictory.

Javascript variables that aren't declared (with var) in a function scope
or as a function argument are dynamic, defaulting to the global object's
property via whatever with() scopes are in place.

The same goes for functions: named functions defined in the global scope
are set as dynamic variables. Named functions defined within a with(X)
in the global scope are put in X. Named functions defined within a
function scope are lexical. I'm not sure what with() within a function
does.

Compare the above with:

function a() {
alert("first");
}

function b() { a() }

function c() {
function a() {
alert("second");
};
b();
}

a();
c();


or accesses any other global property would be a closure:
[...]
That is correct. Probably that is why Flanagan made his oversimplifying
false statement.

Which statement?

That one cited in
<bc992427-bf06-4308-8416-b82396340578@xxxxxxxxxxxxxxxxxxxxxxxxxx>

Different thread, same source of confusion. Sigh. [psf 10.1]

I don't see the connection.

Joost.
.



Relevant Pages

  • Re: Restricting A Function To Be In Scope of Constructor Method
    ... scope) function is just an external function no fricking matter what, ... External functions know nothing about custom objects they appertain to ... Static protected method constructor of a class constructor. ... completely independent from the Global scope. ...
    (comp.lang.javascript)
  • Re: Universal Groups
    ... Groups with global scope ... For example, to give five users access to a particular printer, you could ... local scope permission to access the new printer. ... with global scope automatically receive access to the new printer. ...
    (microsoft.public.windows.server.migration)
  • Re: A "does global variable exist" function
    ... irrelevance of such a function (a simple typeof test should be ... is impossible to use eval to run code with global scope, ... that this question is not asking for a script injection solution ... constructor) in a nested local scope without pollution from the ...
    (comp.lang.javascript)
  • Variable Scope in Include Files
    ... file that declares a constant DAY_NUM. ... but then I get a new one where index.php refers to ... I was assuming that any constant had global scope and therefore when I ...
    (comp.lang.php)
  • Re: Doubts about Linkage Rules
    ... As file scope spans the whole of the file. ... with the previous notation i mean: the scope of the first declaration ... and the second declaration "masks" the first declaration from line 8 ...
    (comp.lang.c)