자바스크립트 클로저 함수에서 변수를 유지하려면 변수를 공백으로 설정하지 마십시오. 현재 다음은
를 호출할 때마다 빈 객체로 설정됩니다.webLinks = {}; 값을 유지하려면 다음 코드를 사용하세요.
var webLink = function (containerId) {
var link1 = "https://www.qries.com",
link2 = “https://www.tutorialspoint.com”;
var webLinks = {};
return function(Id) {
webLinks [id] = "My " + id;
document.write(webLinks);
}
})();