typescript

 
 
> npm install -g typescript
tsc greeter.ts
 

 

/**
 * Created by Administrator on 2018/11/17.
 */
enum SEX{
    MAN,
    WOMAN
}
//枚舉可用到swith(w)
//        case:SEX.MAN

class People {
    //類中不能寫let
    public name:string = "張三";
    //只讀屬性必須在聲明時或構造函數裏被初始化
    readonly name1: string;
    readonly numberOfLegs: number = 8;

    //靜態屬性在類型用People.調用
    static origin = {x: 0, y: 0};

    constructor(){
        alert("aaaaa");
    }
    getName():void{

    }
    //不容許
    /*private class Child{

    }*/

}

var pp = new People();
pp.getName();

//var a = 123;
//a ="asdf";    不能把字符串賦給number類型
//var b = null;    b = '1212'; null賦值後不能再賦值
/**
 * function add(a,b){}
 * add()  不能夠  參數必須對應
 *
 *
 */


var a:number|string;

let set = SEX.MAN;

//聲明外部變量  引jquery
declare var $;
$(function () {

});

window.onload = function () {
    alert('1212');
}
//函數簽名
// success(a:string,b:string)=>void;   方法沒有返回值

var point:{x:number,y:number,z?:number};
//z  可選

//接口定義規範
interface  P{
    x:string,
    y:string
}
//定義一個對象p  必須符合P
var p:P;

p = {
    x:'張三',
    y:'12'
}
//泛型  限定一種類型
class Fanxing<T>{
    a:T;
    b:T;
}

var obj = new Fanxing<number>()

//抽象方法 必須在抽象類中定義
//抽象方法
//abstract makeSound(): void;
//abstract class Department {  }
相關文章
相關標籤/搜索