extend-prototype
- Extends one class with methods from another.
- Supports getters and setters.
- Can (optionally) make use of a whitelist.
- Can easily be added to a class as a static method.
Packaged as a Node.js module.
Installation
npm install extend-prototype --save
The module exposes a single function.
Function Parameters
target
: The object/class to extend.sources
: An object/class (or an array of objects/classes) with methods to add to the target.methodWhitelist
: An array of the names of methods to add. (If omitted, all methods are added.)overwrite
: Whether or not to overwrite existing methods in the target.
Function Signatures
The function can accept its arguments in a variety of combinations:
sourcesourcesourcesource
Usage Examples
Basic Example
const extend = {} {} { return 'example' }const a = aavalue // 'example'
Static Method Example
Easily use extend-prototype
as a static method on your mixin, like so:
{}Mixinextend = {}Mixin const test = test
Example with Arguments
The following example makes use of the methodWhitelist
and overwrite
parameters:
const extend = { return 'from A' } { return 'from B' } {} // Only add the `include` method, and overwrite the existing one. const a = a // 'from B'typeof aexclude // 'undefined'