When function foo is invoked, the [[Call]] method is called and an execution context is created. IIUC, as part of the creation of the execution context, an environment record for str is created and added to the lexical environment within the execution context.
So I "know" how JavaScript logically keeps track of str.
When control moves to the line with the anonymous function expression, a function object is created, and then executed. Does the specification define a position in the execution context to store a reference to such a function object, or, does it not, because the function object is part of an expression and a reference to it is simply thrown away, unless it is assigned to something with a name?
In this instance, there is presumably a logical period when the anonymous function object exists, but has not yet been invoked as part of the IIFE, so a reference to the function object might be expected to exist for this short period, or is the IIFE indivisible?
function foo() {
const str = 'foo';
(function() { })();
}
foo()
Does the specification define a position in the execution context to store a reference to such a function object
No.
the function object is part of an expression and a reference to it is simply thrown away, unless it is assigned to something with a name?
Precisely that.
there is presumably a logical period when the anonymous function object exists, but has not yet been invoked as part of the IIFE, so a reference to the function object might be expected to exist for this short period, or is the IIFE indivisible?
Well, the reference to the function exists inside the expression interpreter of course, somewhere in RAM the engine keeps a pointer to the object. But no, this has nothing to do with the scope that the expression is evaluated in, it does not create a variable binding for it.
From a JS perspective, the expression is indivisible, you cannot inspect its state anyhow without changing the expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With