Skip to content

Instantly share code, notes, and snippets.

@shinypb
Created January 24, 2011 04:38
Show Gist options
  • Save shinypb/792841 to your computer and use it in GitHub Desktop.
Save shinypb/792841 to your computer and use it in GitHub Desktop.
bind: function(that, func) {
if(typeof(func) !== 'function') {
// Only functions can be bound, but for readability of calling code, we
// don't want to worry about calling bind on non-functions.
return func;
}
if(func.bind) {
// Use built-in implementation of bind
return func.bind(that);
}
return function() {
return func.apply(that, arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment