0.1.2 • Published 10 months ago

traitorous v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

VERY simple implementation of traits mechanism in Javascript.

Why Traitorous? Because there already is a package named traitor, dedicated to the same cause :-)

usage

  • initialite a trait via Trait function. You can assign Trait to a variable and use it that way, or simply call the function.
Trait('MyTrait`, {
    property: 'value',
    method: function(){

    }
})

const OtherTrait = Trait('MyOtherTrait', {
    property2: 'secondvalue'
})
  • apply traits to a class via Traits function:
class WithTraits extends Traits('MyTrait', 'MyOtherTrait'){

}

// alternatively, you can extend from trait classes:
class WithTraits2 extends Traits(OtherTrait){

}

Trait-check classes via instanceof:

 instanceOf Trait('HasTrait')
 instanceOf IsOtherTrait

Trait-check for multiple traits:

hasTraits(yourObject, 'traitName1', TraitInstance2)
0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.9

10 months ago