Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
/ merge-context Public archive

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

License

Notifications You must be signed in to change notification settings

balderdashy/merge-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

merge-context

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

Install

$ npm install merge-context

Usage

var mergeCtx = require('merge-context');

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

// someFunction();
// $ undefined

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

// someFunction();
// $ true

.all( objOfFunctions, stuff )

To do an object of functions all at once (like _.bindAll)

var mergeCtx = require('merge-context');

var someObject = {
  foo: function () { ... },
  bar: function () { ... },
  baz: function () { ... }
};
someObject = mergeCtx.all(someObject, {
  sails: require('sails')
});

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

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

License

MIT © Mike McNeil 2014

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published