You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 17, 2025. It is now read-only.
I'm looking for a traits implementation in JS and found this one is pretty interesting.
As you know, Node.js has a util.inherits method to simplify inheritance.
In terms of traits, it seems we need a similar util function that can combine util.inherits and traits together, that's what I have written.
I use lodash extend method for simplicity.
function inherits(constructor, parentConstructor, trait, properties) {
util.inherits(constructor, parentConstructor);
if (properties !== undefined)
_.extend(constructor.prototype, properties);
if (trait !== undefined)
constructor.prototype = trait.create(constructor.prototype);
}