4 ms·
Unfortunately, people voting on StackOverflow are not always correct. If you want the correct answer without guessing, you can check the ECMAScript spec itself:
by goto11 7y ago
Unfortunately, people voting on StackOverflow are not always correct. If you want the correct answer without guessing, you can check the ECMAScript spec itself:
8.3.2 GetThisEnvironment ( )
The abstract operation GetThisEnvironment finds the Environment Record that currently supplies the binding of the keyword this. GetThisEnvironment performs the following steps:
1. Let lex be the running execution context’s LexicalEnvironment.
2. Repeat
a. Let envRec be lex’s EnvironmentRecord.
b. Let exists be envRec.HasThisBinding().
c. If exists is true, return envRec.
d. Let outer be the value of lex’s outer environment reference.
e. Let lex be outer.
NOTE The loop in step 2 will always terminate because the list of environments always ends with the global environment which has a this binding.
Source: http://www.ecma-international.org/ecma-262/6.0/#sec-getthisenvironment http://www.ecma-international.org/ecma-262/6.0/#sec-getthise...
This is pretty unambiguous. The "this" binding is resolved in the lexical scope, not the dynamic scope.