dynamic-scope
Create dynamic scope in JavaScript with "with statement" trick.
It is a native ES2017 module, it provides complete dynamic scope implementation in non-strict mode and incomplete dynamic scope implementation in strict mode.
Of course, closure variables will be lost.
Installation
yarn add dynamic-scope
Usage
{ console} const dynamicFuncExpression = // Non-strict mode; { const message = 'Hello' const func = // Hello World!} // Strict mode; { 'use strict' const func = message: 'Hello' // Hello World!}
API
Table of Contents
createDynamicScopeExpression
Create dynamic scope in JavaScript with "with statement" trick.
Parameters
fn
function The function needs to convert
Returns string An expression needs eval() to active, eval(expression) will return (context) => function