TypeScrict記錄

1、聲明變量時,要標明變量的類型

      如:let test:string = "nihao"
2、聲明函數時,要標明返回數據的類型
3、引用類型有 Array、new String、date、正則表達式
4、字符串的方法有.length  .indexOf()  . lastIndexOf()  .剪切.substring("2","3")    替換.repalce("你好","我好")
5、變量的作用域:局部變量 和全局變量。。元祖

6、什麼是類,一種事物的集合,有屬性和構造函數

7、通過new 一個類生成的實例叫對象

class XiaoJieJie{  //類
    name:string;
    age:number;
    constructor (name:string,age:number){
        this.name = name;
        this.age = age;
    };
    say(){
        console.log("你好這裏是南方航空!")
    }
}
let recall:XiaoJieJie = new XiaoJieJie("小紅",20)   //對象
console.log(recall)
recall.say()

8、修飾符:public(都可訪問)、protested(本類和子類可訪)、private (本類可訪)

9、繼承

class JsShuai extends Jspang{
    public xingxiang:string = '帥氣'
    public zhuangQian(){
        console.log('一天賺一個小目標')
    }
}
let shuai = new JsShuai("技術帥",5,'演講')
shuai.interst()   //使用父類的方法
shuai.zhuangQian()  //調用子類自身擴展的方法

10、重寫,在子類重寫父類的方法,方法名要一樣

11、接口 interface Husband{   }

12、命名空間:

namespace shuaiGe{
    export class Dehua{
        public name:string = '劉德華'
        talk(){
            console.log('我是帥哥劉德華')
        }
    }
}
let dehua1:shuaiGe.Dehua   = new shuaiGe.Dehua()

dehua1.talk()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章