javascript Angular.js Backbone.js 和其他 MV* 模式的 js 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12955337/
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-26 17:30:51  来源:igfitidea点击:

Angular.js Backbone.js and other MV* patterned js libraries?

javascriptweb-applicationsbackbone.jsframeworksknockout.js

提问by Razort4x

I am quite newbie to web application, and more specifically to this MV*pattern. We are making a web application and we thinking of departing from jQuery, not completely, but we are trying to implement a client side language with MVC, MVVM, or MVP support. Basically something that separates views from model. Being new to this MV*pattern I stumbled upon this site.

我是网络应用程序的新手,更具体地说是这种MV*模式。我们正在制作一个 Web 应用程序,我们考虑脱离 jQuery,并非完全脱离,但我们正在尝试实现具有 MVC、MVVM 或 MVP 支持的客户端语言。基本上是将视图与模型分开的东西。作为这种MV*模式的新手,我偶然发现了这个网站

It basically list (almost!) all client side language/framework that support this MV*pattern, and after visiting it I am really confused. Because according to this site..

它基本上列出(几乎!)所有支持这种MV*模式的客户端语言/框架,在访问它之后我真的很困惑。因为根据这个网站..

At the end of the day, Ember.js is the only framework which has everything I desire. I recently ported a relatively small Backbone.js application over to Ember.js and, despite some small performance issues, I am much happier with the resulting code base. Being championed by Yehuda Katz, the community around Ember.js is also amazing. This is definitely the framework to watch out for.

归根结底,Ember.js 是唯一拥有我想要的一切的框架。我最近将一个相对较小的 Backbone.js 应用程序移植到 Ember.js,尽管存在一些小的性能问题,但我对生成的代码库感到满意。在 Yehuda Katz 的拥护下,Ember.js 周围的社区也很棒。这绝对是需要注意的框架。

But on SO, I found this, and it makes me think that angular is much better, while on SO again, this, and thiswhich makes me think it might be backbone what I am looking for.

但是在 SO 上,我发现了this,这让我觉得 angular 好多了,而在 SO 上,thisthis这让我觉得它可能是我正在寻找的支柱。

To make the matter worse, the tests show totally different result. Here

更糟糕的是,测试显示出完全不同的结果。这里

http://jsfiddle.net/HusVw/1/Backbone clear winner

http://jsfiddle.net/HusVw/1/Backbone clear winner

http://jsfiddle.net/ericf/NrpcQ/Backbone winner again

http://jsfiddle.net/ericf/NrpcQ/Backbone winner again

http://jsperf.com/angular-vs-knockout-vs-extjs-vs-backbone/2angular winner for less data for more its knockout

http://jsperf.com/angular-vs-knockout-vs-extjs-vs-backbone/2angular winner for less data for more its knockout

http://jsperf.com/knockout-js-vs-direct-dom-manipulation/3Backbone again

http://jsperf.com/knockout-js-vs-direct-dom-manipulation/3Backbone again

http://jsperf.com/angular-vs-knockout-vs-ember/33no way its ember as the site mentioned

http://jsperf.com/angular-vs-knockout-vs-ember/33no way its ember as the site mentioned

So, basically this all is totally confusing me, I can't decide what in web's name I should learn, and what should I implement in the site. As in tests Backboneclearly stands out, but I've heard a lot about knockout, but the SO links I mentioned say about angular? I know it might be dependent on the application I am currently developing, but I want a broader view, what would be useful not only for this project, but for a longer term? In which case you'd prefer which framework? Or Should I just learn them all?(jk, can't really do that in a plausible time.)

所以,基本上这一切都让我感到困惑,我无法决定我应该以网络的名义学习什么,以及我应该在网站中实施什么。由于在测试中Backbone明显脱颖而出,但我听说过很多关于knockout,但我提到的 SO 链接说的是angular?我知道这可能取决于我目前正在开发的应用程序,但我想要一个更广阔的视野,什么不仅对这个项目有用,而且对长期有用?在哪种情况下,您更喜欢哪个框架?还是我应该把它们全部学完?(jk,在合理的时间内真的不能这样做。)

To make things more f**** up, I heard about dart, and wikisays..

为了让事情更糟,我听说了dart维基说..

The goal of Dart is "ultimately to replace JavaScript as the lingua franca of web development on the open web platform."

Dart 的目标是“最终取代 JavaScript,成为开放 Web 平台上 Web 开发的通用语言”。

So if js is going to be replaced, why the hack I am even considering learning these js libraries/framework(s)?

因此,如果 js 将被替换,为什么我什至在考虑学习这些 js 库/框架?

So, basically, its all messed up and I am totally confused? Can any one please help me decide?

所以,基本上,一切都搞砸了,我完全糊涂了?有人可以帮我决定吗?

采纳答案by Martin S.

There is probably no objective answer, but here's my 2 cents:

可能没有客观的答案,但这是我的 2 美分:

Backbone usually leads to much larger code bases that are more difficult to maintain. Similar to the anecdote in your links, I've worked on one project where the code shrank from 2500 lines with Backbone to 600 lines with Angular. Knockout probably would have yielded equally small (=good) results. My colleagues have moved away from Backbone to Knockout and were much happier afterwards.

主干通常会导致更难维护的更大的代码库。与您链接中的轶事类似,我参与了一个项目,其中代码从 Backbone 的 2500 行缩减到 Angular 的 600 行。淘汰赛可能会产生同样小的(=好的)结果。我的同事们已经从 Backbone 搬到了 Knockout,之后更开心了。

The advantage of Backbone is that it is really lightweight and gives you more options to structure things. That also means you can do more performance tuning, so it can be faster. Those very same aspects are also its disadvantage: You needto structure things yourself which means: more code, more complicated and potentially more bugs.

Backbone 的优势在于它非常轻巧,并为您提供了更多构建事物的选择。这也意味着您可以进行更多的性能调整,因此速度会更快。这些非常相同的方面也是它的缺点:您需要自己构建事物,这意味着:更多的代码、更复杂和潜在的更多错误。

Regarding the tests you mention: They are hardly objective, since they emphasize one very particular use case. Also, they were posted by the author of Backbone himself, so obviously they show Backbone in a good light. For normal UIs, performance should not be a problem no matter which of the 3 (Backbone, Angular, Knockout) you choose. One caveat for Angular: If you want to dynamically display more than 2000 elements on your page, it could be problematic (see the answer of Angular's creator himself here: How does data binding work in AngularJS?).

关于您提到的测试:它们几乎不客观,因为它们强调一个非常特殊的用例。此外,它们是由 Backbone 的作者本人发布的,因此显然它们很好地展示了 Backbone。对于普通 UI,无论您选择 3 个(Backbone、Angular、Knockout)中的哪一个,性能都不应该成为问题。Angular 的一个警告:如果你想在你的页面上动态显示超过 2000 个元素,它可能会出现问题(参见 Angular 的创建者自己的回答:数据绑定如何在 AngularJS 中工作?)。

About Dart: Its goal is to be a language, not just a MV* framework within a language. That is a completely different beast and if you simply need a MV* framework, Dart would be overkill. Also, Dart is still very young and not natively supported in most browsers.

关于 Dart:它的目标是成为一种语言,而不仅仅是一种语言中的 MV* 框架。这是一个完全不同的野兽,如果您只需要一个 MV* 框架,那么 Dart 就显得过分了。此外,Dart 还很年轻,大多数浏览器都没有原生支持。

回答by alexandernst

Well, first of all, there really isn't any "good" answer to this question. All MVC libraries are good if you ask their creators :p That said, I'd recommend you start reading the examples in TODO-MVCso you can see how much code is required for a simple TO-DO web-application, and how complex is. Then decide yourself what are you willing to go with. My personal recommendation is Backbone. Also, there are some complementary libraries that will do (almost) magical stuff, like Backbone Nestedfor example.

嗯,首先,这个问题真的没有任何“好的”答案。如果你问他们的创建者,所有 MVC 库都很好 :p 也就是说,我建议你开始阅读TODO-MVC 中的示例,这样你就可以了解一个简单的 TO-DO web 应用程序需要多少代码,以及有多复杂是。然后自己决定你愿意接受什么。我个人的推荐是 Backbone。此外,还有一些补充库可以做(几乎)神奇的事情,例如Backbone Nested

Good luck!

祝你好运!