Home  >  Q&A  >  body text

javascript - Why can a class still call it even if it does not define the login method and getUserInfo method?

There are the following statements in WxService:

class Service {
    ....没有找到login和getUserInfo的定义
    }
export default Service

There are the following statements in app.js:

import WxService from 'helpers/WxService'
APP({
    WxService: new WxService,
    getUserInfo() {
        return this.WxService.login()
        .then(data => {
            console.log(data)
            return this.WxService.getUserInfo()
        })
        .then(data => {
            console.log(data)
            this.globalData.userInfo = data.userInfo
            return this.globalData.userInfo
        })
    },
})

Why can this.WxService.login() and this.WxService.getUserInfo() be executed?

PHP中文网PHP中文网2645 days ago650

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-26 10:59:41

    Thanks for the invitation.

    This.WxService is the object packaged by WeChat and is hidden from the outside world.

    ps: In addition, WeChat has its own protocol weixin:// similar to http://

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-26 10:59:41

    this.WxService is the object packaged by Weixin
    https://mp.weixin.qq.com/debu...

    wx.getUserInfo({
      success: function(res) {
        var userInfo = res.userInfo
        var nickName = userInfo.nickName
        var avatarUrl = userInfo.avatarUrl
        var gender = userInfo.gender //性别 0:未知、1:男、2:女
        var province = userInfo.province
        var city = userInfo.city
        var country = userInfo.country
      }
    })

    reply
    0
  • Cancelreply