对,就是这样。
在使用lambda定义方法(aka Arrow Functions)的场景下,微信web开发助手里自带的ES6编译器babel.js会把函数里的this替换成undefined。
关于这个问题的出处:

Babel assumes that all input code is an ES2015 module. ES2015 modules are implicitly strict mode so this means that top-level this is not window in the browser nor is it exports in node.

If you don’t want this behaviour then you have the option of disabling strict in the es2015-modules-transform.

PLEASE NOTE: If you do this you’re willingly deviating from the spec and this may cause future interop issues.

Ref: https://babeljs.io/faq/#why-is-this-being-remapped-to-undefined-

行了,别偷懒了,定义方法的时候用classic的function语法吧。

标签: WeChat, 微信, 小程序, 微信小程序, babel.js

添加新评论