lamda 中的 this 是undefined
发布于 4 年前 作者 baiqiang 11938 次浏览 来自 问答

Page({

    data:{ xx : null },

    sthfunc1 : () => { 

        this.setData({xx:1})   // lamda这里的this 是undefined  

    },

    sthfunc2 : function() {

        this.setData({xx:2})  // 这里的this 是有对象的。

    }

})

有人遇到么?

2 回复

es6箭头函数没有this

Page({

    data:{ xx : null },

    sthfunc1() { // 得这么写啊

        this.setData({xx:1})     

    },

    sthfunc2 : function() {

        this.setData({xx:2})  // 这里的this 是有对象的。

    }

})

回到顶部