I'm trying to create some dynamic functions that require an enclosing scope. Currently this works:
eval("with (scope) (function () {return scope.prop})")
This approach seems a bit hacky. User supplied code is nowhere near this so I'm not worried about security, it's just that it seems like there should be a better way.
I know the Function
constructor does not include anything apart from the global scope, but I was hoping there was some way to 'inject' scope into the Function
constructor. Not call or apply or bind, but construct a function with a defined scope.
Is it possible to define a scope when using the Function
constructor? Is it something that may be included in the standard in the future?