javascript BackboneJS vs JavaScriptMVC vs KnockoutJS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5149480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:10:01  来源:igfitidea点击:

BackboneJS vs JavaScriptMVC vs KnockoutJS

javascriptbackbone.jsknockout.jsjavascriptmvc

提问by Drew

I want to use a JavaScript framework for a complex web application. I have been looking at Backbone.js, knockout.js and JavaScriptMVC. Being pretty new to client side JavaScript heavy web apps, I'm not sure which one to pick. Each one has a pretty different approach to separate the concerns. Model/View/Controller vs Model/View/ViewModel vs Model/View/Collection.

我想将 JavaScript 框架用于复杂的 Web 应用程序。我一直在研究 Backbone.js、knockout.js 和 JavaScriptMVC。作为客户端 JavaScript 重型网络应用程序的新手,我不确定该选择哪一个。每个人都有一种非常不同的方法来分离关注点。模型/视图/控制器 vs 模型/视图/视图模型 vs 模型/视图/集合。

What do you guys think? What are the deciding factors? Which one would be the easiest to pick up? What has your experience been like?

你们有什么感想?决定因素是什么?哪一个最容易上手?你的经历是怎样的?

回答by AlexGad

You can't go wrong either way especially if you are building a complex javascript UI. If you choose not to use either, you will likely wind up with a lot of difficult to debug code. I personally like Backbone but they are both lightweight and allow you freedom in your templating language (I use JQuery templates). I think what made me choose Backbone was the way Knockout mixed its components in with your html:

无论哪种方式都不会出错,尤其是在构建复杂的 javascript UI 时。如果您选择不使用它们,您可能会遇到很多难以调试的代码。我个人喜欢 Backbone,但它们都是轻量级的,并且允许您自由使用模板语言(我使用 JQuery 模板)。我认为让我选择 Backbone 的原因是 Knockout 将其组件与您的 html 混合的方式:

<span data-bind="text: myItems().count"></span>

You may be able to avoid using constructs like the above with Knockout but that was enough to throw me toward Backbone. I also liked the fact that backbone has dependencies on both underscore and jquery which were already in use in my projects.

您可能可以避免在 Knockout 中使用上述结构,但这足以让我转向 Backbone。我还喜欢这样一个事实,即主干依赖于我的项目中已经使用的下划线和 jquery。

回答by dylanized

To build on HostDude's comment - it's a feature, not a bug :) Part of the concept of knockout is that there's a layer inbetween your Controller/Model and the View. This lets us modularize our HTML into small components that include the data mapping.

以 HostDude 的评论为基础 - 这是一个功能,而不是一个错误 :) 淘汰赛的部分概念是在您的控制器/模型和视图之间有一个层。这让我们可以将 HTML 模块化为包含数据映射的小组件。

So yes the JS bindings are mixed in, but they are not mixed into raw HTML - rather they are added to tiny modularized Jquery templates. By adding those data bindings in explicitly at the jQuery template level, we have total control over what's mapped to what -- without disturbing our underlying application data model at all :) I love Knockout!

所以是的,JS 绑定被混合了,但它们没有混合到原始 HTML 中 - 而是它们被添加到微小的模块化 Jquery 模板中。通过在 jQuery 模板级别显式添加这些数据绑定,我们可以完全控制映射到什么的内容——根本不会干扰我们的底层应用程序数据模型:) 我喜欢 Knockout!