From cb53ce7ea3c444ab77ef07c62c43da696578da3c Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Mon, 3 Aug 2020 09:37:41 +0530 Subject: [PATCH] update post: Closure and this - How are variables resolved within functions? --- ckddoqwv80154xvs198jkaa5m.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ckddoqwv80154xvs198jkaa5m.md b/ckddoqwv80154xvs198jkaa5m.md index c5fa8a6..9ace100 100644 --- a/ckddoqwv80154xvs198jkaa5m.md +++ b/ckddoqwv80154xvs198jkaa5m.md @@ -160,6 +160,7 @@ These two methods are implemented on all types of environments (scope). Here is | Environment Type | HasThisBinding() | GetThisBinding() | |--------|--------|---------------| +| function | true/false | [[ThisValue]] | | block scope | false | - | | module | true | undefined | | global | true | global object | @@ -169,8 +170,8 @@ These two methods are implemented on all types of environments (scope). Here is Now, back to the special resolving logic for `this`. It will do - -Starting from the FunctionEnvironment (i.e. current function scope), -a. if `env.HasThisBinding()`, then return `env.GetThisBinding()` +Starting from the FunctionEnvironment (i.e. current function scope), +a. if `env.HasThisBinding()`, then return `env.GetThisBinding()` b. else, move up to parent scope and repeat. It will finally reach global scope, which always provides a `this` value (global object). For modules, it will stop at the module scope - whose `this` value is `undefined`.