0.0.4 • Published 9 years ago
unto v0.0.4
unto
This library extends Object.prototype with a single function, unto.
unto accepts a callback, and calls it with the object it was called on.
All objects can method chain with anonymous callbacks.
Installation
npm install untoExample
require('unto').englobal()
// this defines a getter on Object.prototype which binds context
[ 'all things whatsoever ye desire'
, 'that men should do'
].unto((you) =>
you.concat('so shall ye do')
).unto((them) =>
them.concat('for this is the law and the prophets')
)
/* -->
[ 'all things whatsoever ye desire',
'that men should do',
'so shall ye do',
'for this is the law and the prophets' ]
*/Call unto on any object. It takes a callback and aditional parameters. The calling context becomes the first argument
'foo'.unto((a,b,c) => [a,b,c], 'bar', 'baz')
// -> [ 'foo', 'bar', 'baz' ]When .unto is called, the object is bound, so binding any other context will not override it.
Note:
To use unto in the repl, you need the option useGlobal: true.
An example repl with unto exposed is provided in this repository. You can run it from the shel with $ ./repl.
License
MIT