index.js 474 B

1234567891011121314151617181920212223
  1. /**
  2. * Slice reference.
  3. */
  4. var slice = [].slice;
  5. /**
  6. * Bind `obj` to `fn`.
  7. *
  8. * @param {Object} obj
  9. * @param {Function|String} fn or string
  10. * @return {Function}
  11. * @api public
  12. */
  13. module.exports = function(obj, fn){
  14. if ('string' == typeof fn) fn = obj[fn];
  15. if ('function' != typeof fn) throw new Error('bind() requires a function');
  16. var args = slice.call(arguments, 2);
  17. return function(){
  18. return fn.apply(obj, args.concat(slice.call(arguments)));
  19. }
  20. };