TypeScript 学习笔记1
2016-02-23 19:58
357 查看
Interfaces
TypeScript 的 type-checking 专注于值的“shape”
interfaces的作用在于命名值使其便于检测,同时作为软件与软件、软件内部交流的工具。
用于检测,编译成JS的话没有相应的语句
TS:
interface Squareconfig {
color: string;
width?: number;
}
function creatsqure(config:Squareconfig){color:string;area:number}{
//...
<pre>var newSquare = {color: "white", area: 100};
}
JS:
function creatsqure(config) { color: string; area: number; }
{
}
Function Type
interface FunctionExm{
(inData:number):boolean
}
var myFunctionExm:FunctionExm;
//...
Array Type
interface Dictionary {
[index: string]: string;//index为number或者string
//describe: string; 编译通过
} Class Type
interface ClockInterface {
currentTime: Date;
setTime(d: Date);
}
class Clock implements ClockInterface {
currentTime: Date;
setTime(d: Date) {
this.currentTime = d;
}
constructor(h: number, m: number) { }
}describe the public side of the class
Extend
<span style="font-size:12px;">interface Shape {
color: string;
}
interface PenStroke {
penWidth: number;
}
interface Square extends Shape, PenStroke {
sideLength: number;
}</span>Hybird
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
var c: Counter;
c(10);
c.reset();
c.interval = 5.0;
TypeScript 的 type-checking 专注于值的“shape”
interfaces的作用在于命名值使其便于检测,同时作为软件与软件、软件内部交流的工具。
用于检测,编译成JS的话没有相应的语句
TS:
interface Squareconfig {
color: string;
width?: number;
}
function creatsqure(config:Squareconfig){color:string;area:number}{
//...
<pre>var newSquare = {color: "white", area: 100};
}
JS:
function creatsqure(config) { color: string; area: number; }
{
var newSquare = {color: "white", area: 100};
}
Function Type
interface FunctionExm{
(inData:number):boolean
}
var myFunctionExm:FunctionExm;
//...
Array Type
interface Dictionary {
[index: string]: string;//index为number或者string
//describe: string; 编译通过
} Class Type
interface ClockInterface {
currentTime: Date;
setTime(d: Date);
}
class Clock implements ClockInterface {
currentTime: Date;
setTime(d: Date) {
this.currentTime = d;
}
constructor(h: number, m: number) { }
}describe the public side of the class
Extend
<span style="font-size:12px;">interface Shape {
color: string;
}
interface PenStroke {
penWidth: number;
}
interface Square extends Shape, PenStroke {
sideLength: number;
}</span>Hybird
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
var c: Counter;
c(10);
c.reset();
c.interval = 5.0;
相关文章推荐
- 关于try{}catch{}的经典面试题
- App被杀掉
- YTU 2405: C语言习题 牛顿迭代法求根
- ios加密算法汇总
- 十天学习PHP之第四天
- CritterAI与Recast Navigation寻路
- Python链接Telnet
- System Service的驱动形式 --- ServiceManager
- shiro登陆后没有返回设置的successUrl?
- Hardware Acceleration
- Java基础语法
- not in null
- Intent简介
- iOS 开发 -- Swift 语法篇 (三) 控制流
- 【POJ 2104】 K-th Number 主席树模板题
- JQuery获取浏览器窗口的可视区域高度和宽度,滚动条高度
- python正则表达式练习篇
- 手动更新Wamp中php版本的方法
- linux系统中删除eth*.bak或者多余的网卡
- Linux文件属性