在PHP中,我可以像这样将变量绑定到lambda:
$locale = "nl_NL";
$info['t'] = function($text, $render) use ($locale) {
return translate($text, $locale);
}
在下面的代码中,fullpath
变量将被覆盖并包含某个时刻的最新调用值。
var tree = {
"foo.js": null,
"bar.js": {
"baz.js": null
}
}
loadScriptTree(tree) {
for (let idx in tree) {
var fullpath = "root/" + idx;
console.log("Loading "+fullpath);
var subtree = tree[idx];
$.getScript(fullpath, function() {
console.log(fullpath+ "loaded.");
loadScriptTree(subtree);
});
}
}
如何将变量绑定到JavaScript中的函数?