Using eval to execute functions

前端 未结 6 1227
太阳男子
太阳男子 2020-12-21 20:18

There is something I don\'t understand about how eval works. Suppose I have a function foo:

function foo() {
    console.log(\"test\");
}

A

6条回答
  •  春和景丽
    2020-12-21 20:42

    you would need to call

    eval("function foo() { console.log(\"foo\"); };" + " foo();");
    

    in order for this to work;

提交回复
热议问题