我有一个 javascript 模块,可以将数据与 dom 巧妙地分开,并为其data
和ui
对象返回一个公共 api:
var PtCalcApp = (function() {
var ptCalc = ptCalc || {};
ptCalc.ui = {
storage: $('#pt-storage'),
backup: {
daily: $('#per-day-data'),
weekly: $('#per-week-data'),
monthly: $('#per-month-data'),
yearly: $('#per-year-data')
},
change: {
yearly: $('#annual-change'),
daily: $('#daily-change')
}
};
ptCalc.data = {
storage: function() {
ptCalc.ui.storage.val()
}
}
return ptCalc;
})();
现在,当我尝试访问这样的数据时:
PtCalcApp.data.storage()
它返回undefined
。这种自调用函数模式我做错了什么?我该如何解决?