我正在尝试在JS中使用某种命名空间。
我想我可能有类似的东西:
var OuterObject = {
var InnerObject = {
settings: {
numArticles: 5,
articleList: $("#article-list"),
moreButton: $("#more-button")
},
init: function() {
s = this.settings;
this.bindUIActions();
},
bindUIActions: function() {
s.moreButton.on("click", function() {
NewsWidget.getMoreArticles(s.numArticles);
});
},
getMoreArticles: function(numToGet) {
// $.ajax or something
// using numToGet as param
}
};
};
怎么可能这样做?
答案 0 :(得分:3)
就像嵌套物体一样:
var OuterObject = {
InnerObject: {
settings: { ... }
init: function() { ... }
}
}
答案 1 :(得分:1)