Created
August 3, 2011 14:02
-
-
Save ibolmo/1122709 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 = function(bind){ | |
var self = this, args = Array.slice(arguments), args = (args.length > 1) ? args.slice(1) : null; | |
return function bound(){ | |
if (this instanceof bound){ | |
var F = function(){}; | |
F.prototype = new self; | |
bind = new F; | |
} | |
args = args.concat(Array.slice(arguments)); | |
var result = !args ? self.call(bind) : self.apply(bind, args); | |
return F ? bind : result; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment