Native JavaScript classes (introduced in ECMAScript 2015) are a welcome addition to the language, but two things bother me about them:You cannot declare properties inside the class (you have to do it in the constructor, which I do not like). Yes, there is a TC39 proposal for this, but it's not yet available to normal users.Classes can only inherit from one single parent class. I guess mix-ins are technically possible, but the syntax is confusing in my opinion.I wrote the class-plus module to provide these features to ES2015 classes using a simple API, while offering some additional niceties. The full set of features are:Provide an easy API to generate classes with additions.Support for adding properties right above the class definition (as close to inside it as we can get).Support for multiple mix-ins, will merge both properties and methods from multiple classes.Support for adding static properties.Optional easy way to mix-in the Node.js EventEmitter class.Optional hook system (async event emitters).Optional automatic conversion of callback methods to async ones.No dependenciesNPM Package - GitHub RepoEnjoy! Or don't!
Submitted May 03, 2019 at 04:07AM by cgijoe_jhuckaby
No comments:
Post a Comment