1

i've been reading the ECMAScript spec(ecma262) quite a bit lately.

and i find the FunctionDeclarationInstantiation abstract operation to be complicated.

can someone explain to me what it does ?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
AngryJohn
  • 576
  • 4
  • 10
  • 2
    It sets up the parameters and all the variable and function declarations in the new environment. The note at the top pretty much sums it up. – Felix Kling Oct 01 '21 at 12:19
  • i see so FunctionDeclarationInstantiation purpose is to hoist all the variables and functions inside the running execution context ? – AngryJohn Oct 01 '21 at 12:21
  • 1
    Basically yes... – Felix Kling Oct 01 '21 at 12:23
  • but it doesn't makes sense if that so why in 14.3.1 Let and Const Declarations it says. "The variables are created when their containing Environment Record is instantiated" from my understanding they are created during runtime – AngryJohn Oct 01 '21 at 12:40
  • `let` and `const` declarations are also created during FunctionDeclarationInstantiation (that's step 34 in https://262.ecma-international.org/12.0/#sec-functiondeclarationinstantiation) but they are not initialized. They are only initialized once the declarations are processed as part of evaluating the function body. In contrast, `var` declarations are immediately initialized (step 28.e.i.5). – Felix Kling Oct 01 '21 at 12:50
  • 1
    Yeah... but i think that's only applied if the `let` or `const` are declared not inside a block. because if it was declared inside a block then why do we have "BlockDeclarationInstantiation ". i think block inside a function doesn't count as the part of the "function body" – AngryJohn Oct 01 '21 at 12:58
  • Oh sure, this only affects `let` and `const` declarations directly inside the function body because `let` and `const` are block scoped. – Felix Kling Oct 01 '21 at 14:17
  • hey dude can you take a look at my latest question "How will the Lexical environment and the Variable Environment will look like at the following code" – AngryJohn Oct 02 '21 at 18:27

1 Answers1

0

From the article: "The abstract operation FunctionDeclarationInstantiation takes arguments func (a function object) and argumentsList. func is the function object for which the execution context is being established."

They further explain the steps going on.

In my own words this is the process of "setting up the environment which the function later runs in". This includes some setup work with the values passed as arguments concerning their default value, if one is present, or the value given in the call to the function.

Vincent Menzel
  • 1,040
  • 1
  • 6
  • 17