Background
With ESM default strict and "use strict"
directive, there is one particular JS feature we lost in the process, a feature that requires mandatory usage of Function(...)
evaluation to be able to escape from strict semantics of the language.
Mavo, Alpine.js, Vue.js, tag-params and many others, use evaluation mostly to be able to use the with(...) statement, or to simply retrieve the global context, like it's done in Angular.
Proposal
Allow escaping from strict semantics through Reflect.applyLegacy(target, thisArgument, argumentsList)
so that:
Reflect.applyLegacy(
function() { return this },
void 0,
[]
) === globalThis;
// true in every env
Reflect.applyLegacy(
function() { with(this) return name; },
{name: 'legacy'},
[]
) === 'legacy';
// true even in strict environments
In short, the idea here is to have some sort of "use sloppy"
directive enabled through a very explicit method name that also suggests it's a bad idea, slow, or unpredictable, yet it completely remove from various code bases the need to have new Function
and CSP or security concerns all together.
Thank you!
P.S. no strong feelings around the name, it just felt aligned with what we have already as Reflect
method and intent, but applyDeprecated
or applySloppy
or applyNonStrict
would work either ways, it's the feature that I'm interested in, not really its name.