You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
474 B
JavaScript
24 lines
474 B
JavaScript
/**
|
|
* Slice reference.
|
|
*/
|
|
|
|
var slice = [].slice;
|
|
|
|
/**
|
|
* Bind `obj` to `fn`.
|
|
*
|
|
* @param {Object} obj
|
|
* @param {Function|String} fn or string
|
|
* @return {Function}
|
|
* @api public
|
|
*/
|
|
|
|
module.exports = function(obj, fn){
|
|
if ('string' == typeof fn) fn = obj[fn];
|
|
if ('function' != typeof fn) throw new Error('bind() requires a function');
|
|
var args = slice.call(arguments, 2);
|
|
return function(){
|
|
return fn.apply(obj, args.concat(slice.call(arguments)));
|
|
}
|
|
};
|