变量 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;
};
答案 0 :(得分:2)
r
的值由实际调用drawElevation
或writeStats
的任何代码提供。