Last active
April 26, 2024 04:52
-
-
Save mertenvg/7097491 to your computer and use it in GitHub Desktop.
Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof Function.prototype.bind === 'undefined') { | |
/** | |
* Function bind(obj[, arg1[, arg2[, ...]]]) polyfill | |
* | |
* @param obj | |
* | |
* @returns {Function} | |
*/ | |
Function.prototype.bind = function (obj) { | |
var fn = this, | |
args = [].slice.call(arguments, 1) || []; | |
if (typeof fn !== "function") { | |
throw new TypeError(fn.toString() + " is not a function. Unable to bind."); | |
} | |
return function () { | |
fn.apply(obj, args.concat([].slice.call(arguments))); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment