108

Typescript--JavaScript that Scales入门

 6 years ago
source link: https://blog.zhitantech.com/typescript-javascript-that-scales/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最近开始尝试在项目中使用Typescript, 简单来说,Typescript是一个JavaScript的超集(即支持JavaScript的全部语法,完全兼容),TS在JavaScript的基础上增加了静态类型检查和面向对象的特性。 Typescript可以在编译阶段“降级”为ES5或ES3,以在浏览器中运行,因此Typescript获得了和JavaScript一样的兼容性,可以在全部的现代浏览器中运行。 npm是安装TypeScript的最简洁的方式。npm install -g typescript即可全局安装,不过我通常会选择安装在项目的依赖中。即npm install typescript,然后通过node_modules/.bin/tsc来运行Typescript的编译器。 Hello World Typescript的文件以ts结尾,我们首先来编写一个greeter.ts的文件。内容如下: function greeter(person){ return "Hello, "+person } let user = "World" document.getElementById('app').innerHTML=greeter(user)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK