The use of the new
keyword in JavaScript is highly divisive, some say that you should avoid it entirely. ES6 classes may seem at odds with this line of thinking, but I will show how you can have your cake and eat it too. Consider a module that exports a class:
export default class {
constructor () { /* Do stuff here. */ }
}
The only way to get an instance out of this module, or rather an object that inherits the prototype of the class object, is to use the new
keyword, which some consider harmful. Personally, I am not against new
, it provides implicit understanding that the returned value is an object with inherited properties.