How can I detect I'm inside an eval() call?

后端 未结 3 878
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 06:40

Does there exist a string s such that

(new Function(s))();

and

eval(s);

behave differently? I\'

3条回答
  •  时光说笑
    2021-02-01 07:08

    if (new Error().stack.indexOf('at eval') > -1) {
        console.log('Oh noo, I am being evaled');
    }
    

提交回复
热议问题