0

变量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;
};
4

1 回答 1

2

的值r由实际调用的任何代码drawElevation或提供writeStats

于 2013-09-12T02:59:23.047 回答