什么是使用ES5的JavaScript角2应用程序和那些使用打字稿的利弊? [英] What are the pros and cons using ES5 JavaScript for Angular 2 applications and those for using TypeScript?

查看:191
本文介绍了什么是使用ES5的JavaScript角2应用程序和那些使用打字稿的利弊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在和1角工作多年,我开始学习如何使用角度,而不是2

I work with Angular 1 for years now, and I'm starting to learn how to use Angular 2 instead.

但是,撰写code中的任何行之前,我挣扎着我是否必须使用打字稿或JavaScript。

But before writing any line of code, I struggle to whether I have to use TypeScript or JavaScript.


  • 有哪些利弊使用打字稿?

  • 什么是那些使用老式的JavaScript?

  • What are the pros and cons using TypeScript ?
  • What are those for using plain old JavaScript ?

奖金的问题:


  • 是否有在角2上下文JavaScript和打字稿之间选择一个最佳实践?

  • Is there a best practice for choosing between JavaScript and TypeScript in an Angular 2 context ?

我不知道,但是打字原稿从code的几件我所看到的,似乎主要特点是:

I don't know TypeScript but from the few pieces of code I have seen, it seems the major features are :


  • 类型提示

  • Type hinting

原型机制最常见的一类语法下隐藏。

Prototype mechanisms hidden under a most common used Class syntax.

我的第一个IM $浏览网页苯磺酸之后$ pssions:

My first impressions after browsing the web :

类型提示:

我爱类型提示,但我认为这是一个有点矫枉过正使用新的语言只是为了添加这一功能,并产生更多的工作,为开发者使用松散类型库(从文档,有一些方法可以做到这一点)。

I love type hinting, but I think it's a little overkill to use a new language just to add this feature and will produce more work for the devs to use libraries with loose type (from the docs, there is some ways to do this).

基于类的styntax:

有关新类语法(这是接近ES6)什么?的原型的JavaScript最容易被误解的功能,但我觉得要了解它是如何工作(知道你真的)不是简单地把它放在一边,这是更重要的。

What about the new class syntax (which is close to the ES6) ? The Prototypes are the most misunderstood feature of JavaScript but I think it's more important to understand how it works (to know what you really do) than simply put it aside.

ES5是基于原型的编程语言,那么为什么要使用基于类的伪编程语言,这将最终产生的原型?这似乎怪我。

ES5 is a Prototype-based programming language so why do you want to use a pseudo Class-based programming language, which will eventually produce prototypes ? It seems weird to me.

code代:

最后一点是关于code发生器。我已经使用code发电机在其他方面,我真的不喜欢它:在大多数情况下,人体会产生更好的书面code(我已经采取了看看生成的JS:匿名函数,匿名函数无处不在!),更简洁(当谈到加载在浏览器中生成的js文件的大小是很重要的,以减少加载)

The last point is about code generator. I've already used code generator in other context, and I don't really like it : in most case, a human will produce a better written code (I have taken a look to the generated js : anonymous functions, anonymous function everywhere !) and more concise (when it comes to load the generated js files in the browser the size is important to reduce loading)

总之:

比如我真的不服气的兴趣去学习,而不是坚持ES5 JavaScript的打字稿。所以,我想有反馈从社区知道使用打字稿的优势。

For instance I'm not really convinced of the interest to learn TypeScript instead of sticking to ES5 JavaScript. So I would like to have feedbacks from the community to know the advantages of using TypeScript.

推荐答案

有没有正确的答案。但是我被要求在工作Angular2在过去的一个月,我一直在做一些关于它的研究和开发。因此,也许一些点可以帮助你:

There is no correct answer to this question. However I was asked to work on Angular2 for the past month and I've been doing some research and development on it. So maybe some points can help you out:


  • code提示仍然没有在集成开发环境的成熟,因为TS仍是新的和仍在变化。

  • Code hinting is still not mature in the IDEs because ts is still new and its still changing.

我同意,他们应该集中精力的原型是JS的强度和方向,如果他们想OOP他们应该使用一个面向对象的语言,而不是,但我能说的,这是毫无disscusion是要去改变什么。

I agree that they should concentrate on prototype which is the strength and orientation of JS, if they want OOP they should use an OOP language instead, but what can I say, no disscusion about it is gonna change anything.

我一直在做这个工作使用TS,我可以告诉你,相比于JS,事情是更具可读性,需要一大堆更多的设置,但TBH这里只有一件事是应该的问题,你和它为什么我去了TS方式:

I've been working on it using TS and I can tell you, compared to js, the thing is more readable, takes whole lot more to setup, but tbh there's only one thing that should matter to you and its why I went the TS way:

有pretty对角2多没有文档,甚至没有官方的API完全写的是,作品的点点在这里,你会发现有要么过时阿尔法语法,不工作或它写在TS。我甚至不得不通过在src code明白我怎么想打电话,因为缺乏它的文档的东西。所以,如果你从现在开始,我强烈建议你走这条路。只要你知道你做了什么,检查Angular.io页面,看到了开发指南,还有写在JS 4个部分,15个在TS,其明显的,他们会推动TS。

There's pretty much no documentation on Angular 2, not even the official API is fully written yet, the little bit of pieces you'll find here and there are either outdated with alpha syntax that doesn't work anymore or its written in TS. I've even had to go through the src code to understand how am I suppose to call something because of the lack of documentation on it. So if you are starting now, I strongly suggest you to go that route. Just so you know what you are getting into, check the Angular.io page and see the Developer guide, there's 4 sections written in JS and 15 in TS, its obvious they'll push for TS.

是否有在角2上下文JavaScript和打字稿之间选择一个最佳实践?

"Is there a best practice for choosing between JavaScript and TypeScript in an Angular 2 context ?"

没有,它的preferences的事,你的项目有多大,你在你的code,你想多么容易在更多的时间开发成本等,以发现缺陷多少estructure想..

No, its a matter of preferences, how big your project is, how much estructure you want in your code, how easy you want to spot defects at the cost of more time developing, etc...

这篇关于什么是使用ES5的JavaScript角2应用程序和那些使用打字稿的利弊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆