函数参数集在哪里?

时间:2013-09-12 02:51:06

标签: google-maps variables definition

变量 r 在哪里定义?我知道它是一个回调函数,但是我没有看到r被赋予了设定值。

var drawElevation = function(r) {
  var max = writeStats(r);
  drawGraph(r, max);
};

var writeStats = function(r) {
  var prevElevation = r[0].elevation;
  var climb = 0;
  var drop = 0;
  var max = 0;
  for (var i = 1; i < r.length; i++) {
    var diff = r[i].elevation - prevElevation;
    prevElevation = r[i].elevation;
    if (diff > 0) {
      climb += diff;
    }
    else {
      drop -= diff;
    }

    if (r[i].elevation > max) {
      max = r[i].elevation;
    }
  }
  max = Math.ceil(max);
  $('#climb-drop').text("Climb: " + Math.round(climb) + "m Drop: " + Math.round(drop) + "m");
  return max;
};

1 个答案:

答案 0 :(得分:2)

r的值由实际调用drawElevationwriteStats的任何代码提供。