枚举部分 Enumeration part 使用枚举我们可以定义一些有名字的数字常量. 枚举通过 enum关键字来定义. Using enumerations, we can define some numeric constants with names. Enumeration is defined by the enum keyword. enum Direction { Up = 1, Down, Left, Right } 枚举是在运行时真正存在的一个对象,其中一个原因是因为这样可以从…
布尔值 Boolean let isDone:boolean=false; 数字 Number let decLiteral:number=6; let hexLiteral:number=0xf00d; 字符串 String let name:string="bob"; name="smith"; 模版字符串 template let name:string=`Gene`; let age:number=37; let sentence:string=`Hello…
软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不仅能够支持当前的数据类型,同时也能支持未来的数据类型, 这在创建大型系统时为你提供了十分灵活的功能. In software engineering, we should not only create well-defined APIs, but also consider reusability. Components can support not only current data types, but al…
我们声明一个 Greeter类.这个类有3个成员:一个叫做greeting的属性,一个构造函数和一个greet方法. We declare a Greeter class. This class has three members: an attribute called greeting, a constructor, and a green method 我们在引用任何一个类成员的时候都用了this.它表示我们访问的是类的成员. We use this when we refer to an…
typescript的核心原则之一就是对所具有的shape类型检查结构性子类型化 One of the core principles of typescript is to check structural subtyping of shape types 在typescript中,接口的作用就是为这些类型命名和为你的代码或第三方代码定义契约 In typescript, the function of an interface is to name these types and defin…
var a=10; function f(){ var message="hello,world"; return message; } function f(){ a=10; return function g(){ var b=a+1; return b; } } var g=f(); g();//11 var 声明有一些奇怪的作用域规则 The var declaration has some strange scoping rules function f(shouldinit…