bind.js 655 B

12345678910111213141516171819
  1. var slice = require('../array/slice');
  2. /**
  3. * Return a function that will execute in the given context, optionally adding any additional supplied parameters to the beginning of the arguments collection.
  4. * @param {Function} fn Function.
  5. * @param {object} context Execution context.
  6. * @param {rest} args Arguments (0...n arguments).
  7. * @return {Function} Wrapped Function.
  8. */
  9. function bind(fn, context, args){
  10. var argsArr = slice(arguments, 2); //curried args
  11. return function(){
  12. return fn.apply(context, argsArr.concat(slice(arguments)));
  13. };
  14. }
  15. module.exports = bind;