This is an awesome recap of the difference between lexical/static scope and dynamic scope as it relates to functions, free variables (lexcial scope) and the infamous
this (dynamic scope). All the credit goes to Dmitry Soshnikov. You can read the rest of his breakdown here: JS scope: static, dynamic, and runtime-augmented
Here's the recap:
- Static (lexical) scope is when a function knows the resolution environment for free variables at time of creation.
- Closures is a natural continuation of the static scope. One can say: “closure == static scope”.
- Dynamic scope is when a caller provides the callee’s resolution environment at activation.
Subscribe to Elliot Sachs
Get the latest posts delivered right to your inbox