0.3.4 • Published 7 years ago
@ampersarnie/implements v0.3.4
Implements
Installation
npm install @ampersarnie/implements
Example
Interfaces
class MyInterface {
myInterfaceMethod() {}
anotherInterfaceMethod(foo, bar) {}
}
export default MyInterface
Traits
class MyTrait {
myTraitMethod() {
return 'Hello world.';
}
}
export default MyTrait
Class
import { Implements } from '@ampersarnie/implements';
import MyInterface from './MyInterface.js';
import MyTrait from './MyTrait.js';
class MyClass {
interfaces() {
return [MyInterface];
}
traits() {
return [MyTrait];
}
myInterfaceMethod() {
// This is an standard interface method.
// ...
// Calling the trait method.
return this.myTraitMethod();
}
anotherInterfaceMethod(foo, bar) {
// This interface method requires the argument params
// foo and bar as dictated by the interface.
}
}
export default new Implements(MyClass);