3 ms·
No. JS engines detect of eval in the AST. It's why you can't rename eval and reference the current scope. const eval2 = eval; (() => { const a = 1;
by paulddraper 2y ago
No. JS engines detect of eval in the AST.
It's why you can't rename eval and reference the current scope.
const eval2 = eval;
(() => {
const a = 1;
eval2("a");
})();
// ReferenceError: a is not defined
---
The reason JS engines choose to share the closure record among all closures create in the function scope is purely for performance.
function f() {
const a = {};
const b = {};
return [
() => a,
() => b,
];
}
Both functions share the same single closure record, referencing a and b.
JavaScript developers have rediscovered this over and over and over again.
* Meteor.js (2013) [1]
* My personal journey (2013) [2]
[1] https://blog.meteor.com/an-interesting-kind-of-javascript-memory-leak-8b47d2e7f156 https://blog.meteor.com/an-interesting-kind-of-javascript-me...
[2] https://stackoverflow.com/questions/19798803/how-javascript-closures-are-garbage-collected https://stackoverflow.com/questions/19798803/how-javascript-...
- Feathercrown 2y agoYou can rename eval, but the renamed eval will be considered "indirect" and will run in the global scope.
- paulddraper 2y agoYes, corrected, thank you.