我想在模块模式中使用javascript创建一些隔离。Javascript模块模式隔离
但是当我运行这段代码:
var mymap = {};
mymap['230'] = (function() {
privatePageLoad = function(nid, page){
console.log('PAGE LOAD from 230: '+nid);
}
function handleDocummentAdded() {
console.log("New Document in 230!");
privatePageLoad(230, 0);
};
return {
newDocument: handleDocummentAdded
}
})();
mymap['318'] = (function() {
privatePageLoad = function(nid, page){
console.log('PAGE LOAD from 318: '+nid);
}
function handleDocummentAdded() {
console.log("New Document in 318!");
privatePageLoad(318, 0);
};
return {
newDocument: handleDocummentAdded
}
})();
mymap['230'].newDocument();
mymap['318'].newDocument();
我得到以下结果:
New Document in 230! (index):29
PAGE LOAD from 318: 230 (index):40
New Document in 318! (index):44
PAGE LOAD from 318: 318
,但我期待:
New Document in 230! (index):29
PAGE LOAD from 230: 230 (index):40
New Document in 318! (index):44
PAGE LOAD from 318: 318
被称为私有方法总是最后加入地图... 我做错了什么?
这里是它的jsfiddle http://jsfiddle.net/jpedro/4xdTA/