Created
October 30, 2014 14:51
-
-
Save ben-bradley/ba37af810b0fe8575360 to your computer and use it in GitHub Desktop.
Fun with bind/call prototypes
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
// 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