0.0.3 • Published 10 years ago

extend-context v0.0.3

Weekly downloads
4
License
-
Repository
github
Last release
10 years ago

extendContext

like .bind() and .bindAll() but extends the context (this) instead of replacing it

Usage:

var extendContext = require('extendContext');

var someFunction = function () { console.log(this.foo); }

// someFunction();
// $ undefined

someFunction = extendContext(someFunction, {
  foo: true
  'and you know, the stuff': 82385235,
  I: 93529523,
  want: 2352,
  'to inject into': 'someFunction\'s `this` variable'
});

// someFunction();
// $ true
To do an object of functions all at once (like _.bindAll)
var someObject = {
  foo: function () { ... },
  bar: function () { ... },
  baz: function () { ... }
};
someObject = extendContext.all(someObject, {
  sails: require('sails')
});

// Now I can do:
someObject.foo();
someObject.bar();
someObject.baz();

// And they'll all have access to `sails`.

License

MIT c. Mike McNeil 2014

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago