Skip to content

Instantly share code, notes, and snippets.

@kurtextrem
Forked from WebReflection/fast-bind.js
Created December 23, 2015 18:50
Show Gist options
  • Save kurtextrem/363398ba68c25d65252f to your computer and use it in GitHub Desktop.
Save kurtextrem/363398ba68c25d65252f to your computer and use it in GitHub Desktop.
Function.prototype.bind is slow in JS, so we fix it plus we have great compatibility (at least for 90% of common cases without partial args)
+function(proto, Object) {
'use strict'
var originalBind = proto.bind
Object.defineProperty(proto, 'bind', {
value: function bind(context) {
var callback = this
return arguments.length === 1 ? function () { return callback.apply(context, arguments) } : originalBind.apply(callback, arguments)
}
})
}(Function.prototype, Object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment