1


当我们在项目中将 Phantomjs 与 Base2 库结合使用时,会出现以下错误:

+ phantomjs ...../src/test/javascript/SpecRunner.html
TypeError: setting a property that has only a getter

谁能指出如何解决这个问题?它似乎是由于 Phantomjs 内部的 Javascript“严格模式”而发生的(请参阅此处),但无法从 Phantomjs 文档中找到如何关闭它,特别是因为它发生在我们需要的外部库(Base2.js)中?

谢谢,
稻田

4

1 回答 1

0

Base2.js does not seem to define "use strict". This means that in one of your javascript files you have a "use strict" line outside of any function. This turns on strict mode at the point it is defined and you can not turn it off again. It is better to turn it on only inside function declarations.

To figure out this problem, search for "use strict" or 'use strict' in all files included in your project. Then remove them or move them inside function bodies.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode

Can I disable ECMAscript strict mode for specific functions?

于 2013-10-07T12:23:42.470 回答