Is there any way to make the code below working?
(function(){
var n = "abc";
(new Function("return alert(n);"))();
})();
If I run the code in browser result is: "Uncaught ReferenceError: n is not defined".
Also, I need to some other variables like n make accessible inside the new Function too.
new Functionat all in this case? There is a big yellow note in the MDN documentation, it can hardly be overlooked: "Note: Functions created with theFunctionconstructor do not create closures to their creation contexts; they always are created in the global scope. [...]"