无法获取实例化类的方法

时间:2018-02-21 11:36:30

标签: javascript class

我有这个类定义,创建实例但不能在类定义中获取方法。

export class Partner {
  constructor (instructorPeer, id) {
    this.instructorPeer = instructorPeer;
    this.id = id;
    this.basePath = `/partners/${this.id}`;
  }

  async call (path, params) {
    return this.instructorPeer.call (
      `/partners/${this.id}/methods/${path}`,
      params
    );
  }

此代码来自另一个使用合作伙伴类创建对象的文件。我用新伙伴创建对象

为什么返回的newPartner对象上没有方法?那我怎么能达到那个cal方法呢?

const partners = {chrome: [], firefox: [], safari: [], ie: []};

const self = this;
const appropriatePartners = await this.retrievePartners (partnerInfo);

async createSession(partnerInfo){     const partners = {chrome:[],firefox:[],safari:[],即:[]};

const self = this;
const appropriatePartners = await this.retrievePartners (partnerInfo);
Object.keys (appropriatePartners).forEach (function (key) {
  appropriatePartners[key].forEach (partner => {
    let newPartner = [new Partner (self.instructorPeer, partner.id)];
    partners[key].push (newPartner);
  });
});

return new Session (partners);

}

这也是另一个使用从那里返回的对象的文件。

const partners = await getTestPartners (capabilities);
partners.chrome[0].call ('connect', myparams);

0 个答案:

没有答案