我是一個C + +(Qt)開發人員,並知道一點JS。我無法理解以下代碼的一部分。你能幫我解決這個問題嗎?JS關閉查詢
function augment(withFn) {
var name, fn;
for (name in window) {
fn = window[name];
if (typeof fn === 'function') {
// **Not able to understand below code.**
window[name] = (function(name, fn) {
var args = arguments;
return function() {
withFn.apply(this, args);
fn.apply(this, arguments);
}
})(name, fn);
// **In above code I understood everything else except this last line.
// Why whole function is in circular bracket? Why it ends with (name, fn);
// What is the meaning of this?
}
}
}
augment(function(name, fn) {
console.log("calling " + name);
});
@Quentin:實際上它不僅僅是關於語法,還有它爲什麼在那裏使用 – zerkms
+1,所有的@zerkms的例子都非常好。 – SunnyShah