kingBook

导航

TypeScript 判断类型

//1. typeof
typeof padding === "number";
typeof padding === "string";
typeof obj === "object";
//2. instanceof
if(padder instanceof SpaceRepeatingPadder){
    //do some things
}
//3. constructor.name
if(this.constructor.name=="Player"){
    //do some things
}

posted on 2020-07-24 09:46  kingBook  阅读(3270)  评论(0编辑  收藏  举报