bind.js 559 B

12345678910111213141516
  1. var restArguments = require('./restArguments.js');
  2. var isFunction = require('./isFunction.js');
  3. var _executeBound = require('./_executeBound.js');
  4. // Create a function bound to a given object (assigning `this`, and arguments,
  5. // optionally).
  6. var bind = restArguments(function(func, context, args) {
  7. if (!isFunction(func)) throw new TypeError('Bind must be called on a function');
  8. var bound = restArguments(function(callArgs) {
  9. return _executeBound(func, bound, context, this, args.concat(callArgs));
  10. });
  11. return bound;
  12. });
  13. module.exports = bind;