在严格模式下,对 eval
的间接调用应该将 this
绑定(bind)到 eval 代码中的全局对象。
10.4.2: In Edition 5, indirect calls to the eval function use the global environment as both the variable environment and lexical environment for the eval code. In Edition 3, the variable and lexical environments of the caller of an indirect eval was used as the environments for the eval code.
但是,在 Opera 中,此表达式会导致 undefined
:
(function(){'use strict'; return (0 || eval)('this'); }())
Chrome 和 Firefox 按预期工作。
我在这里找到了这个:http://kangax.github.com/jstests/indirect-eval-testsuite/
这是浏览器错误吗?如果是这样,它是否正在被跟踪?
另见 Why do some forms of indirect eval fail in Opera and Safari?
最佳答案
Opera 的 ECMAScript 引擎似乎在这里做了一些过于急切的优化,其中“(0||eval)”在编译之前被简化为“eval”。在这种情况下,这种优化引入了一个错误,因为它改变了代码的行为。
(在 Opera 内部,我们将此问题跟踪为 CORE-47727)
关于javascript - 为什么 (0 || eval) 在 Opera 中不被视为间接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666447/