Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.
This repository was archived by the owner on May 17, 2025. It is now read-only.

Add a inherits method to complement util.inherits #3

@oliverzy

Description

@oliverzy

Hi,

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions