Javascriptで完全に機能する次の関数があります
function graphite_get_data(target) {
return context.metric(function(start, stop, step, callback) {
var fetch_time = new Date().getTime();
if ((fetch_time-current_time) < 6000 && saved_data.length > 0) {
callback(null, graphite_parse(saved_data));
}
else {
// -------------- Begin Request New Data ------------------
d3.json(host + "/render?format=json"
+ "&target=" + encodeURIComponent(target)
+ "&from=" + graphite_format_date(start - 2 * step)
+ "&until=" + graphite_format_date(stop - 1000),
function(data) {
if (!data) return callback(new Error("unable to load data"));
current_time = fetch_time
saved_data = data;
callback(null, graphite_parse(data));
});
// -------------- End Request New Data --------------------
} // else
}); // return
}
http://js2coffee.orgを使用してこれを coffeescript に変換しようとすると、機能せず、デバッグ方法がわかりません。
graphite_get_data = (target) ->
console.log(global_pod)
console.log("hi") #prints
context.metric (start, stop, step, callback) ->
console.log("hi") #doesn't print
fetch_time = new Date().getTime()
if (fetch_time - current_time) < 6000 and saved_data.length > 0
callback null, graphite_parse(saved_data) # will use global variable test_pod
else
# -------------- Begin Request New Data ------------------
d3.json host + "/render?format=json" + "&target=" + encodeURIComponent(target) + "&from=" + graphite_format_date(start - 2 * step) + "&until=" + graphite_format_date(stop - 1000), (data) ->
return callback(new Error("unable to load data")) unless data
current_time = fetch_time
saved_data = data
callback null, graphite_parse(data) #will use global variable test_pod
# -------------- End Request New Data --------------------
コーヒースクリプトをデバッグする方法を教えてもらえますか?
編集:生成されたJavaScriptを確認し、これを見ました
graphite_get_data = function(target) {
var fetch_time;
console.log("hi");
context.metric(function(start, stop, step, callback) {});
fetch_time = new Date().getTime();
console.log("hi");
if ((fetch_time - current_time) < 6000 && saved_data.length > 0) {
callback(null, graphite_parse(saved_data));
return true;
}
else {
d3.json(host + "/render?format=json" + "&target=" + encodeURIComponent(target) + "&from=" + graphite_format_date(start - 2 * step) + "&until=" + graphite_format_date(stop - 1000), function(data) {
if (!data) {
return callback(new Error("unable to load data"));
} // end if
current_time = fetch_time;
saved_data = data;
callback(null, graphite_parse(data));
return true;
}); //end function(data)
return true;
} //end else
// missing });
};
graphite_format_date = function(time) {
return Math.floor(time / 1000);
};
return graphite_parse = function(data) {
var pod_data, pod_json_data;
pod_json_data = $.grep(data, function(e) { return e.target === test_pod; });
pod_data = pod_json_data[0]["datapoints"].slice(1).map(function(d) { return d[0]; });
return pod_data;
};
}
}); // what is this here?? it should be in missing
}).call(this);
問題は});であることがわかりました。ある場所で欠落し、別の間違った場所で追加されました
まだそれを修正する方法に取り組んでいます