我想像这样构建我的应用程序:
APP.open = (function ($) {
return {
people: function() {
return {
gender: function() {},
age: function() {}
}
}
};
}(jQuery));
我可以获得APP.open.people()
,但是当我这样做时:APP.open.people.gender();
我得到undefined
.
最佳答案
您可以执行以下操作来实现您的要求: 请注意围绕 people 分配的匿名函数。
APP.open = (function ($) {
return {
people: (function() {
return {
gender: function() {},
age: function() {}
}
})()
};
}(jQuery));
关于javascript 在 return 中返回项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779117/