README
Extending
Create extremely simple extendable objects.
var extending = require('extending');
// Create initial object
var foo = extending({ foo: 1 });
console.log(foo.foo);
// Extend off it by calling it as a function
var bar = foo({ bar: 2 });
// Continue extending with new objects.
var baz = bar({ baz: 3 });
console.log([ baz.foo, baz.bar, baz.baz ]);
// => [1, 2, 3]
Installation
$ npm install --save extending
var extending = require('extending');
API
extending([object])
Create an easily extendable object.
object
(Object
): Object to start with (default:{}
).
Returns an "extendable", a function with your object's properties that can be called to extend.
Example:
var foo = extending({ ... });
var bar = foo({ ... });
var baz = bar({ ... });
// ...
extendable([object])
The result of calling extending
, your extendable object.
object
(Object
): Extension on the original object.
This function has the properties of your object.
Helper extendable.toObject()
Create an object from the extendable.
Example:
var foo = extending({ foo: 1, bar: 2 });
foo.toObject();
// => { foo: 1, bar: 2 }
Helper extendable.extend([object])
An alias to calling the extendable function.
object
(Object
): Extension on the original object.
Example:
var foo = extending({ foo: 1 });
var bar = foo.extend({ bar: 2 });
var baz = bar.extend({ baz: 3 });
// ...
Helper extendable.toJSON()
Serialize your extendables into JSON.
Example:
var foo = extending({ foo: 1 });
var bar = foo.extend({ bar: 2 });
var baz = bar.extend({ baz: 3 });
JSON.stringify(baz);
// => "{ \"foo\": 1, \"bar\": 2, \"baz\": 3 }"
Credits
Jamen Marzonie |
License
MIT © Jamen Marzonie