diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2016-03-29 09:04:39 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2016-03-29 09:04:39 +0300 |
commit | b9abf087eb9761c27be27b5d81852f29e24a58c3 (patch) | |
tree | 91c3cb79bc4b2b87b8f323e6ebc9bb18ed6aaf0d | |
parent | cb99ca030f5f8456ee8afdb6e778909130e46e58 (diff) |
Remove all Function.bind calls
https://github.com/feross/webtorrent-desktop/issues/256
-rw-r--r-- | lib/torrent.js | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index aad46b5..2cc0800 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -223,8 +223,12 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) { }, maxConns: self.client.maxConns }) - self.swarm.on('error', self._onError.bind(self)) - self.swarm.on('wire', self._onWire.bind(self)) + self.swarm.on('error', function (err) { + self._onError(err) + }) + self.swarm.on('wire', function (wire, addr) { + self._onWire(wire, addr) + }) self.swarm.on('download', function (downloaded) { self.client._downloadSpeed(downloaded) // update overall client stats @@ -240,7 +244,9 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) { // listen for peers (note: in the browser, this is a no-op and callback is called on // next tick) - self.swarm.listen(self.client.torrentPort, self._onSwarmListening.bind(self)) + self.swarm.listen(self.client.torrentPort, function () { + self._onSwarmListening() + }) self.emit('infoHash', self.infoHash) } @@ -298,7 +304,9 @@ Torrent.prototype._onSwarmListening = function () { peerId: self.client.peerId, port: self.client.torrentPort }) - self.discovery.on('error', self._onError.bind(self)) + self.discovery.on('error', function (err) { + self._onError(err) + }) self.discovery.on('peer', function (peer) { // Don't create new outgoing TCP connections when torrent is done if (typeof peer === 'string' && self.done) return @@ -342,7 +350,9 @@ Torrent.prototype._onMetadata = function (metadata) { self.discovery.setTorrent(self) // add web seed urls (BEP19) - if (self.urlList) self.urlList.forEach(self.addWebSeed.bind(self)) + self.urlList.forEach(function (url) { + self.addWebSeed(url) + }) self.rarityMap = new RarityMap(self.swarm, self.pieces.length) @@ -426,7 +436,9 @@ Torrent.prototype._onStore = function () { // start off selecting the entire torrent with low priority self.select(0, self.pieces.length - 1, false) - self._rechokeIntervalId = setInterval(self._rechoke.bind(self), RECHOKE_INTERVAL) + self._rechokeIntervalId = setInterval(function () { + self._rechoke() + }, RECHOKE_INTERVAL) if (self._rechokeIntervalId.unref) self._rechokeIntervalId.unref() self.ready = true @@ -778,9 +790,16 @@ Torrent.prototype._onWireWithMetadata = function (wire) { Torrent.prototype._updateSelections = function () { var self = this if (!self.swarm || self.destroyed) return - if (!self.metadata) return self.once('metadata', self._updateSelections.bind(self)) + if (!self.metadata) { + self.once('metadata', function () { + self._updateSelections() + }) + return + } - process.nextTick(self._gcSelections.bind(self)) + process.nextTick(function () { + self._gcSelections() + }) self._updateInterest() self._update() } |