A way to construct Functions with custom scopes?
#!/JoePea
joe at trusktr.io
Wed Jun 10 18:06:34 UTC 2020
For example, what if we could write something like
```js
function foo() {
var x = 10
}
const [scope, returnValue] = scope from foo()
// can't do anything with `scope` directly, it's like an empty object
(an exotic object?).
console.log(getOwnAndInheritedKeys(scope)) // empty array
new Function('console.log(x)', { scope }) // logs 10
```
Or something.
Maybe we can pass objects, and the keys are used for scope, similar to
`with`, but they are passed by reference into the scope:
```js
new Function('console.log(x)', { scope: { x: 10 } }) // logs 10
```
I think this would open up the doors to frameworks that want to create
expressions in things like Element attributes, to make it easy for
those expression to have access to certain variables. Currently it is
difficult to make this happen; the cleanest ways of doing it involve
build steps. With this idea we would not need build steps to have a
clean way of doing it.
#!/JoePea
More information about the es-discuss
mailing list