objextender
v0.0.3 object prototype extend
objExtender
Extends the Object Prototype safely using ES6 Symbols
Install
$ npm install --save objextender
Usage
const extend = require( 'objextender' );
let get = extend( {
keys: function () {
return Object.keys( this )
}
} )
let x = {
a: 1,
b: 2
}
x[ get.keys ]()
//=> [ 'a', 'b' ]
API
objextender(input, [options])
input
Type: object
input
must be in a format where the values of any given key is a function
options
getHelperMethod
Type: boolean
Default: true
This allows you to choose whether you would like the provided get helper method which allows you to do this:
let please = extend( {
grabX: function ( get ) {
return get( 'x' );
}
} )
let y = {
x: 34
}
y[ please.grabX ]()
//=> 34
toExtend
Type: object(but really a class)
Default: Object (the class)
This allows you to choose what object you would like to be extending the prototype of safely. Like so:
let classyClass = function () {
this.x = 'magic'
};
let please = fn( {
grabX: function ( get ) {
return get( 'x' );
}
}, {
toExtend: classyClass
} )
let objectOfClass = new classyClass();
objectOfClass[ please.grabX ]()
//=> 'magic'
License
MIT © Nick The Sick