Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

async 在 weex 使用时遇到的问题

编译 ES6 的工具是一样的,在 weex 项目中则报错。尝试过各种解决方案都失败了。

最简单的试验代码

async function f() {
    return 'hello world';
}
f().then(v => console.log(v))
Uncaught TypeError: Cannot assign to read only property 'constructor' of object '#<Object>'
    at eval (runtime.js:106)
    at Object.eval (runtime.js:716)
    at eval (runtime.js:725)
    at Object.845 (index.js:1079)
    at __webpack_require__ (index.js:22)
    at Object.eval (runtime-module.js:19)
    at eval (runtime-module.js:33)
    at Object.844 (index.js:1072)
    at __webpack_require__ (index.js:22)
    at eval (index.js:1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

报错原因是因为 Weex 用了严格模式,而且冻结了原生对象的原型(Object.prototypeArray.prototype 等),所以不能重写原型上的方法,尤其 constructor

这个错可能是 async 的 polyfill 报出来的。里边还用了 eval 是怎么回事?严格模式下会有问题的。

如果不是强需求,在浏览器支持之前暂时先别用 async,polyfill 也会影响性能的。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...