Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Created October 30, 2014 14:51
Show Gist options
  • Save ben-bradley/ba37af810b0fe8575360 to your computer and use it in GitHub Desktop.
Save ben-bradley/ba37af810b0fe8575360 to your computer and use it in GitHub Desktop.
Fun with bind/call prototypes
// https://variadic.me/posts/2013-10-22-bind-call-and-apply-in-javascript.html
var bind = Function.prototype.call.bind(Function.prototype.bind);
var Ping = function(host, option) {
// do stuff
return this;
}
Ping.prototype.send = function() {
// do more stuff
}
Ping.prototype.start = function (callback) {
var send = bind(this.send, this);
this.interval = setInterval(function () {
send(callback);
}, this.options.interval);
send(callback);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment