I was trying to make a package of npm
, something simple:
class Hello {
constructor(world){
this._world = world | 'world';
}
world(){
return this._world;
}
}
module.exports = Hello;
After doing tests I wanted to initialize it in the following way:
var Hello = require('Hello')('world');
console.log(Hello.world());
But he returned the following error
Class constructor Hello can not be invoked without 'new'
What should I change in my module and / or class to initialize it in that way?
And do not have to do something like this:
var Hello = require('Hello');
var hello = new Hello('world');
console.log(hello.world());