1.0.0-1 • Published 10 years ago
polyplug v1.0.0-1
polyplug
Simple plugin system
This is prerelease software.
Usage
const polyplug = require('polyplug')
class A {
constructor() {
this.initialize()
this.bar()
}
}
class B {
initialize() {
// ...
}
bar()
}
polyplug(A, B)Assume A is the main class and B is the plugin class.
The above will merge B's prototype into A's, just like a mixin. This won't make instances of A instances of B, though.
This also assumes no instances of B will ever be created. Instead, plugin classes can declare initialize(). When polyplug(A, B) is called, the definition of B's initialize() will be added to A's. Essentially, calling (new A).initialize() will first call A.prototype.initialze() followed by B.prototype.initialize.
This initialize() functionality is optional and can be missing from either A or B.
All members visible to Object.getOwnPropertyNames() and Object.getOwnPropertySymbols will be copied.
License
MIT
1.0.0-1
10 years ago