您的位置:首页技术文章
文章详情页

javascript - 为什么一个类没有定义login方法和getUserInfo方法却还能调用?

【字号: 日期:2023-05-15 16:34:32浏览:43作者:猪猪

问题描述

在WxService中有如下语句:

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

在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}) },})

为什么可以执行this.WxService.login()和this.WxService.getUserInfo()?

问题解答

回答1:

谢邀。

this.WxService是微信封装的对象,对外是隐藏的。

ps:另外微信还有自己的协议weixin://类似http://

回答2:

this.WxService是微信封装的对象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 }})

标签: JavaScript
相关文章: