Created
August 12, 2014 06:11
-
-
Save zdying/5efbe115104eadabd35a to your computer and use it in GitHub Desktop.
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
/** | |
* Function.prototype.bind | |
*/ | |
if (!isFunc(Function.prototype.bind)){ | |
Function.prototype.bind = function(thisArg){ | |
if(!isFunc(this)){ | |
throw new TypeError("Bind must be called on a function") | |
} | |
var slice = [].slice, | |
self = this, | |
bindArgs = slice.call(arguments, 1), | |
newFunc = function(){ | |
self.apply( | |
this instanceof newFunc ? this : (thisArg || {}), | |
bindArgs.concat(slice.call(arguments)) | |
) | |
}; | |
newFunc.prototype = self.prototype; | |
return newFunc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment