From 53fb62e09644b8ac4f01eb0ddaaf6dc6cd77235e Mon Sep 17 00:00:00 2001 From: SCG82 Date: Tue, 9 Feb 2021 05:00:51 -0800 Subject: [PATCH] Use unique names for nested callbacks (#397) --- speedtest.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/speedtest.js b/speedtest.js index 48d47d8..54d14f7 100644 --- a/speedtest.js +++ b/speedtest.js @@ -191,9 +191,9 @@ Speedtest.prototype = { throw "You can't select a server while the test is running"; } if (this._selectServerCalled) throw "selectServer already called"; else this._selectServerCalled=true; - /*this function goes through a list of servers. For each server, the ping is measured, then the server with the function result is called with the best server, or null if all the servers were down. + /*this function goes through a list of servers. For each server, the ping is measured, then the server with the function selected is called with the best server, or null if all the servers were down. */ - var select = function(serverList, result) { + var select = function(serverList, selected) { //pings the specified URL, then calls the function result. Result will receive a parameter which is either the time it took to ping the URL, or -1 if something went wrong. var PING_TIMEOUT = 2000; var USE_PING_TIMEOUT = true; //will be disabled on unsupported browsers @@ -201,7 +201,7 @@ Speedtest.prototype = { //IE11 doesn't support XHR timeout USE_PING_TIMEOUT = false; } - var ping = function(url, result) { + var ping = function(url, rtt) { url += (url.match(/\?/) ? "&" : "?") + "cors=true"; var xhr = new XMLHttpRequest(); var t = new Date().getTime(); @@ -217,11 +217,11 @@ Speedtest.prototype = { if (d <= 0) d = p.duration; if (d > 0 && d < instspd) instspd = d; } catch (e) {} - result(instspd); - } else result(-1); + rtt(instspd); + } else rtt(-1); }.bind(this); xhr.onerror = function() { - result(-1); + rtt(-1); }.bind(this); xhr.open("GET", url); if (USE_PING_TIMEOUT) { @@ -271,7 +271,7 @@ Speedtest.prototype = { ) bestServer = serverList[i]; } - result(bestServer); + selected(bestServer); }.bind(this); var nextServer = function() { if (i == serverList.length) {