function与=>的区别
发布于 6 年前 作者 clu 11338 次浏览 来自 问答

APP.JS内

//获取设备宽高
wx.getSystemInfo({
success:function(res) {
this.globalData.syHeight = res.windowHeight
this.globalData.syWidth = res.windowWidth
},
globalData: {
userInfo: null,
syWidth:null,
syHeight: null
},
//会报错,读取不到globalData
//改成这样就可以了:
//获取设备宽高
wx.getSystemInfo({
success:res =>{
this.globalData.syHeight = res.windowHeight
this.globalData.syWidth = res.windowWidth
},
//function与=>的区别
// function中this是使用时的对象
// =>中的this是定义时的对象

1 回复

应该是报了undefined的错,区别请查询es6箭头函数

回到顶部