소스 검색

Use unique names for nested callbacks (#397)

SCG82 5 년 전
부모
커밋
53fb62e096
1개의 변경된 파일7개의 추가작업 그리고 7개의 파일을 삭제
  1. 7 7
      speedtest.js

+ 7 - 7
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) {