html52.com
我爱小程序-开发者交流社区

小程序开发中如何在第三方js中使用prototype进行this调用

如下代码,想请教如何像JS代码一样调用对应的方法,如this._connect();

JS代码如下:

function Client(host, i, pwd) {
 
  this.host = host || 'ws://localhost:80';
  this._connect();
}
 
Client.prototype._connect = function() {
  console.log('test connect! ');
};
 
var c = new Client({
          user: 'xiaoming',
          client_type: '1'
        }, '123456', false);


小程序中utils加入 以进代码进行方法导出:

module.exports = {
Client: Client,
}


遇到问题 Client方法中this._connect()错误,请问如何在小程序第三方引入的js中进行类使用?

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付