Created
April 6, 2013 03:15
-
-
Save bfricka/5324578 to your computer and use it in GitHub Desktop.
Bind Polyfill in Coffeescript
This file contains 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
unless Function::bind | |
Function::bind = (oThis) -> | |
# closest thing possible to the ECMAScript 5 internal IsCallable function | |
if typeof this isnt "function" | |
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable") | |
aArgs = Array::slice.call(arguments, 1) | |
fToBind = this | |
fNOP = -> | |
fBound = -> | |
fToBind.apply (if this instanceof fNOP then this else oThis), aArgs.concat(Array::slice.call(arguments)) | |
fNOP:: = @:: | |
fBound:: = new fNOP() | |
fBound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment