我有一個類Node.js的要求類構造函數的參數
class advertHandler {
constructor(projects) {
this.projects = projects;
}
getProject(name) {
return this.projects[name];
}
}
module.exports = new advertHandler(projects);
當我嘗試使用它像這樣
const advertHandler = require('./advertHandler')(projectsArray);
advertHandler.getProject('test');
它拋出異常,require is not a function
,但沒有構造一切都很好,所以問題是如何使用類構造函數與需求?
檢查這個答案http://stackoverflow.com/questions/30689817/es6-call-class-constructor-without-new-keyword – MyUserInStackOverflow