0.2.0 • Published 8 years ago

extending v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Extending Build State

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.

extendable.toObject() Helper

Create an object from the extendable.

Example:

var foo = extending({ foo: 1, bar: 2 });
foo.toObject();
// => { foo: 1, bar: 2 }

extendable.extend([object]) Helper

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 });
// ...

extendable.toJSON() Helper

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
Jamen Marzonie

License

MIT © Jamen Marzonie

0.2.0

8 years ago

0.1.0

8 years ago