好的。我想了解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)。 –