为什么这里需要加上this?

发布于 6 年前作者 xia018390 次浏览最后编辑 6 年前来自 ask

this.mapCtx = wx.createMapContext(‘myMap’)
    this.mapCtx.getCenterLocation({
      success: function (res) {
        console.log(res.longitude)
        console.log(res.latitude)
      }
    })

直接 var mapCtx = wx.createMapContext(‘myMap’)为什么不行?

1 回复
fanping
fanping1 楼4 年前

赋给this是方便在别的地方调用该实例吧。