Skip to content

Instantly share code, notes, and snippets.

@nathggns
Created October 25, 2013 10:20
Show Gist options
  • Save nathggns/7152556 to your computer and use it in GitHub Desktop.
Save nathggns/7152556 to your computer and use it in GitHub Desktop.
/**
* Returns a function that uses it's first argument as the context
* for a callback
* @param {Function} callback The callback to call
* @return {Function}
*/
function context(callback) {
return function() {
var args = Array.prototype.slice.call(arguments);
var context = args.shift() || this;
return callback.apply(context, args);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment