Usually, a function remembers where it was born in the special property. It references the Lexical Environment from where it’s created.
But when a function is created using new Function
, I am getting an error
My code:
function fun() {
let x = 12;
let y = new Function('console.log(x)');
return y;
}
fun()(); // error: x is not defined
Does new Function
does not support the closure concept of javascript Or Did I mess something wrong?
Thanks in advance