eval(fn) and eval(arrowFn) returns different value

前端 未结 4 788
小鲜肉
小鲜肉 2021-01-26 09:13

As per the Mozilla docs in order to execute a function using eval it must be wrapped inside ( ) i.e. if you don\'t use them then it treate

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-26 09:28

    In your example, a is declared as it's a named function. In the second case, you just write an expression which is a lambda function. See here and here.

    If you want to get the same effect for fn, do

    `console.log(eval("var a = function(){}"))`; //`function(){}`.
    

提交回复
热议问题