【发布时间】:2018-05-30 01:10:50
【问题描述】:
例如这是否适合模型:
var Model = function Model(){
this.chapterIndex = 0;
this.pageIndex = 0;
this.next = true;
this.prev = false;
this.getCurrentpage = function getCurrentPage(){
return chapterList[this.chapterIndex].pages[this.pageIndex];
};
this.getChapterPageLength = function getChapterPageLength(){
return chapterList[this.chapterIndex].pages.length;
};
this.getTotalChapters = function getTotalChapters(){
return chapterList.length;
};
this.canGoForwardInChapters = function canGoForwardInChapters(){
return this.chapterIndex + 1 < this.getTotalChapters();
};
}
还是应该在控制器中处理 cangoForwardInChapters 之类的函数?
最佳做法是什么?
我阅读了 https://www.sitepoint.com/mvc-design-pattern-javascript/ 作为参考,引导我来到这里。
【问题讨论】:
-
StackOverflow 不是询问最佳实践的最佳场所。更多的是:“此代码不起作用,这是错误消息(或预期与实际行为)。我该如何解决?”我们更喜欢可以标记为正确的问题。最佳实践问题取决于个人喜好和您需要处理的其余代码,并且可能有多个不同但仍然“正确”的答案
标签: javascript model-view-controller model javascriptmvc