AngularJS 2 - 使用哪种语言?(打字稿、Javascript、Dart)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35129269/
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
AngularJS 2 - Which language to use? (Typescript, Javascript, Dart)
提问by Elfayer
With AngularJS 2 coming out, the documentation is suggesting three languages :
Typescript
, Javascript
and Dart
.
随着 AngularJS 2 的推出,文档建议使用三种语言:
Typescript
,Javascript
和Dart
.
I'm only used to Javascript EcmaScript 5 and am wondering what are the strength and weakness of these three ?
我只习惯了 Javascript EcmaScript 5,想知道这三个的优缺点是什么?
At the time this question is asked, the documentation is more developed on Typescript and pretty slim on the others (even their own language Dart):
在提出这个问题时,文档在 Typescript 上更发达,而在其他文档上(甚至是他们自己的语言 Dart):
- Typescript:4 Tutorials, 16 Developer Guides, 4 Testing Guides
- Javascript:0 Tutorials, 4 Developer Guides, 0 Testing Guides
- Dart:0 Tutorials, 14 Developer Guides, 0 Testing guides
- 打字稿:4 篇教程、16 篇开发者指南、4 篇测试指南
- Javascript:0 教程,4 开发人员指南,0 测试指南
- Dart:0 个教程,14 个开发人员指南,0 个测试指南
Should I change my habit of developing using Javascript and follow what Angular 2 is suggesting by using Typescript ? Does it really change the concepts of Javascript ?
我应该改变我使用 Javascript 开发的习惯并遵循 Angular 2 建议使用 Typescript 吗?它真的改变了 Javascript 的概念吗?
AngularJS 2.0official website
采纳答案by Günter Z?chbauer
Dart makes it easy to start because everything you need is provided by the Darts ecosystem out of one hand (language, package management, build, ...).
Dart 让您轻松上手,因为您需要的一切都由 Darts 生态系统单手提供(语言、包管理、构建……)。
TypeScript
打字稿
For TS there are the most resources available (documentation, ...) because there is a huge user base.
对于 TS,有最多的可用资源(文档,...),因为有庞大的用户群。
The Dart and JS version of Angular is generated from TS.There seem to be lots of issues to get a Angular+TS project up and running (see Angular2 questions here on SO) but there are seed projects available where everything is set up already. I don't know details because I'm using only Dart myself.
Angular的Dart 和JS 版本是从 TS 生成的。启动和运行 Angular+TS 项目似乎有很多问题(请参阅此处的 Angular2 问题 SO),但有可用的种子项目,其中一切都已设置。我不知道细节,因为我自己只使用 Dart。
For TS there is now Angular CLIwhich improves the developer experience a lot for Angular2 with TypeScript.
对于 TS,现在有Angular CLI,它通过 TypeScript 极大地改善了 Angular2 的开发人员体验。
JavaScript, ES5, ES6
JavaScript、ES5、ES6
If you're a JS purist, it might be the right language for you. If not (if you were you probably wouldn't ask this question) then I'm quite sure you're better off using Dart or TS. Angular makes use of type annotations in several ways. With JS there are "workarounds" needed, where otherwise a simple type annotation is enough (mostly dependency injection).
如果您是 JS 纯粹主义者,那么它可能是适合您的语言。如果不是(如果你是你可能不会问这个问题)那么我很确定你最好使用 Dart 或 TS。Angular 以多种方式使用类型注解。使用 JS 需要“解决方法”,否则一个简单的类型注释就足够了(主要是依赖注入)。
Dart
镖
Dart is a nice language with a set of tools that work well together. A lot of issues the JS/TS environment causes are solved elegantly for Dart.
Dart 是一种很好的语言,具有一组可以很好地协同工作的工具。Dart 优雅地解决了 JS/TS 环境导致的很多问题。
Since about 2016/05 Angular2 Dart is an independent project and differs quite a lot from the TS and JS versions (as of 2016/10).
自 2016/05 年左右开始,Angular2 Dart 是一个独立项目,与 TS 和 JS 版本(截至 2016/10 年)有很大不同。
The Router module that was replaced in TS several times to make it work with offline template compilation, wasn't replaced in Dart because in Dart lazy loading also works fine with the "old" router.
... and also
NgModule
wasn't introduced to Dart for the same reason.The new Forms module built for TS wasn't ported (yet) to Dart.
Dart had offline template compilation from the beginning but doesn't support the browser-platform-dynamic to compile components at runtime.
A new Dependency Injection module seems to be work in progress for Dart based on Dagger2 (currently not yet available) to replace the DI system that was auto-generated from TypeScript code.
Angular2 Dart has a strong focus on build output size and runtime performance but AFAIK support for multi-platform support (like server-side rendering) was dropped.
在 TS 中多次替换路由器模块以使其适用于离线模板编译,但在 Dart 中没有替换,因为在 Dart 中延迟加载也适用于“旧”路由器。
... 也
NgModule
没有因为同样的原因被介绍给 Dart。为 TS 构建的新 Forms 模块(尚未)移植到 Dart。
Dart 从一开始就有离线模板编译,但不支持浏览器平台动态在运行时编译组件。
基于 Dagger2(目前尚不可用)的 Dart 似乎正在开发一个新的依赖注入模块,以取代从 TypeScript 代码自动生成的 DI 系统。
Angular2 Dart 非常关注构建输出大小和运行时性能,但 AFAIK 对多平台支持(如服务器端渲染)的支持被放弃了。