Define a scope for javascript Function constructor
问题 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