function higher_order() {
    var add = function (x, y) {
        return x + y;
    }
    var sub = function (x, y) {
        return x - y;
    }
    calc(1, 5, add);
    calc(7, 6, sub);
}
function calc(x, y, f) {
    return f(x, y);
}これを,XMLHttpRequestで利用。
function getJson(uri, func) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200) {
var linksJson = req.responseText;
var data;
eval("data = " + linksJson);
func(data);
}
}
req.open("GET", uri, true);
req.send(null);
}
function process1() {
var func = function (data) {
// process
}
getJson("hoge.json", func);
}
 
0 件のコメント:
コメントを投稿