You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
474 B

4 years ago
  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. };