TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JavaScript MVC

59 点作者 naish将近 16 年前

4 条评论

jerf将近 16 年前
Pure MVC isn't possible for most Javascript apps, because the Model lives on the server. Now we're talking something like MMVC (Model-server, model-client, view, controller). Oh, and the controller isn't just controlling the view, it eventually has to feedback to the actual server model, so it's more like MMVCC. Oh, and if you want the page to load concrete HTML for the initial view of the data (for speed, since dynamically constructing it client side may be slow), then we've got MMVVCC.<p>Now, I know some sites don't have that last one, but MMVCC is pretty common.<p>Now that following MMVVCC has mucked up your code beyond belief, maybe you should reconsider whether it actually bought you anything.<p>Upshot: The MVC abstraction just doesn't make sense in this context. It cuts the wrong way for a client-server application, and if you're just forcing your code into MVC's structure because there's this dogma floating around that it's a good idea... don't do that! There are far better ways to structure your JS. In fact, almost anything is a better way to structure your JS.
评论 #770760 未加载
评论 #771308 未加载
评论 #770743 未加载
评论 #771824 未加载
olegp将近 16 年前
Also worth taking a look at json-template: <a href="http://code.google.com/p/json-template/" rel="nofollow">http://code.google.com/p/json-template/</a>
评论 #770659 未加载
评论 #770783 未加载
mgreenbe将近 16 年前
MVC never made a great deal of sense to me, in that I've never really seen a system that entirely embodies what's described. Nevertheless, programming Javascript is tough because it's easy to confuse the DOM---the view---with the client-side model. When updates can come from the server or the view, maintaining the client side model is quite difficult.<p>Plug: Flapjax &#60;<a href="http://flapjax-lang.org/&#62" rel="nofollow">http://flapjax-lang.org/&#62</a>; helps with this a bit. My own thesis work used Flapjax to prototype an even more robust system.
hendler将近 16 年前
Many design patterns work perfectly well in Javascript.<p>In web architectures, there is a practical problem with where logic lives, where the data lives, and what generates the "view". It's a non trivial architectural problem, but it's not impossible by any means. The computer science and software is completely capable.<p>I guess this is tangential to the debate about if Javascript is _good_ for MVC. If code is executed on both the server and the browser there probably needs to be a clean separation of responsibility or code generation. Otherwise - Google gears and chrome OS can certainly make the entire app live completely client side (and in MVC/ JS).