+ 3

Closures of function-object constructors. Fix this code or Elaborate this code

//basic code let person = new Function("a","b","return a+b"); console.log("Non-Error: "+person(1,2));//3 //own code let personA = new Function("a","b","return ()=>a+b"); console.log("Error 1: "+personA(1,2));//Error 1:()=> a+b //own method let createperson = new Function("name","age", "return function(){ let user = {};user.name=name;user.age=age;return user;}"); console.log("Error 2: "+createperson.name); //Error 1:anonymous

12th Dec 2019, 9:20 AM
Vinay Govardhanam
Vinay Govardhanam - avatar
1 Réponse
+ 3
According to the code Error 1 : ()=> a+b; I think it's returns a string of method which is function defined in an object
12th Dec 2019, 9:23 AM
Vinay Govardhanam
Vinay Govardhanam - avatar