执行微信代码报错:
WAService.js:3 thirdScriptError
this.setData is not a function;at pages/index/index onLoad function;at setTimeout callback function
TypeError: this.setData is not a function
at Function.<anonymous> (http://127.0.0.1:9973/appservice/pages/index/index.js:53:12)
at http://127.0.0.1:9973/appservice/__dev__/WAService.js:3:13773
at http://127.0.0.1:9973/appservice/__dev__/WAService.js:8:5308
代码如图:
把this改成getApp()错误依旧:
解决方法:在函数中加入var that = this;修改后如图
总结:
1、如果函数作为对象的方法调用,this指向的是这个上级对象,即调用方法的对象。
2、如果是构造函数中的this,则this指向新创建的对象本身。