好的。我想了解JavaScript中的閉包。 我有一個功能,但我看到不一致的結果。當傳遞url參數時,除非在回調中完成,否則沒關係。我認爲閉幕會保留這個功能的價值。瞭解將變量作爲JavaScript變量傳遞時變量會發生什麼變化
ABC.print = function (reportId, format, reportTitle) {
alert("Coming in=" + format); // Always has right value.
var url = 'Main/MyModule/Print?reportId=' + reportId;
url += '&format=' + format;
url += '&reportTitle=' + reportTitle;
function printWindow(urlString) {
window.open(urlString, 'Print', "toolbar=no,menubar=no,status=no");
};
// What is the difference between?
if (someCondition)
{
// Variables in url are not current, they retain first time value only.
SomeFunction("Text", "Text 2", function() { printWindow(url); });
}
else {
// Variables are always current
printWindow();
}
};
[你,而這個檢查(https://www.google.com.bd/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=javascript%20scope)。 –