Skip to content

Instantly share code, notes, and snippets.

@yuya
Created June 9, 2014 06:29
Show Gist options
  • Select an option

  • Save yuya/f47cc8b4f0bb5ed83824 to your computer and use it in GitHub Desktop.

Select an option

Save yuya/f47cc8b4f0bb5ed83824 to your computer and use it in GitHub Desktop.
Function::bind Polyfill
unless Function::bind
Function::bind = (obj) ->
unless typeof this is "function"
throw new TypeError "Function.prototype.bind - what is trying to be bound is not callable"
slice = [].slice
args = slice.call(arguments, 1)
method = this
noop = ->
bound = ->
return method.apply(
if this instanceof noop then this else obj or window,
args.concat(slice.call(arguments))
)
return bound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment