2021年1月18日星期一

Nodejs - class function not being recongnized

Hi I am new to JS and Node.

I have this class

foo.mjs

  class Foo extends BarInterface {    constructor(configFilePath) {      super();      this.type = 'mytype';      this.name = 'foo';    }    name() {      return this.name;    }    type() {      return this.type;    }  }  ...  export default new Foo(configFilePath);  

in manager.mjs I import foo

  import foo from './foo/foo.mjs';    class Manager {    constructor(memberList){      this.registry = {}      memberList.forEach(d => {        this.register(d);      });    }    register(m) {      if (!m instanceof BarInterface) {        throw new Error(`${m} must have implement BarInterface`);      }      this.deviceHandlers[m.type()] = m; <------------HERE I SEE AN ERROR    }  }  

above when I call m.type() is telling me that TypeError: foo.type is not a function but type() is defined in the class in foo.mjs? whats going on here?

https://stackoverflow.com/questions/65784174/nodejs-class-function-not-being-recongnized January 19, 2021 at 09:05AM

没有评论:

发表评论