Using eval to execute functions

前端 未结 6 1225
太阳男子
太阳男子 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:44

    The main thing you should understand about eval is that it is evil. Don't use it... ever. There is always a way to achieve the same thing by dynamically creating a script document or by using a closure.

    Read Douglas Crockford: JavaScript the good parts.

提交回复
热议问题