typesctipt抽象类
abstract class Person {
abstract hobby()
}
class Juge extends Person{
hobby(){
return '深渊疲劳'
}
}
class Niuheng extends Person{
hobby(){
return '代码使我快乐'
}
}
class Haoge extends Person{
hobby(){
return '螺蛳粉'
}
}
枚举
let addOrEdit = ['add', 'edit']
function getHobby(value: number) {
if (value === 0) {
return '下象棋'
} else if (value === 1) {
return '画画'
} else if (value === 2) {
return '追剧'
} else if (value === 3) {
return '看纪录片'
}
}
function getHobby(value:number) {
switch (value) {
case 0:
return '下象棋'
case 1:
return '画画'
case 2:
return '追剧'
case 3:
return '看纪录片'
default:
break;
}
}
const Hobbys = {
ChineseCheess: 0,
Draw: 1,
Moves: 2,
Documentary: 3
}
function getHobby(value: number) {
if (value === Hobbys.ChineseCheess) {
return '下象棋'
} else if (value === Hobbys.Draw) {
return '画画'
} else if (value === Hobbys.Moves) {
return '追剧'
} else if (value === Hobbys.Documentary) {
return '看纪录片'
}
}
enum Hobbys {
ChineseCheess,
Draw,
Moves,
Documentary
}
console.log('Hobbys[0]', Hobbys[0]);
console.log('type',typeof Hobbys[0]);
function getHobby(value: number) {
if (value === Hobbys.ChineseCheess) {
return '下象棋'
} else if (value === Hobbys.Draw) {
return '画画'
} else if (value === Hobbys.Moves) {
return '追剧'
} else if (value === Hobbys.Documentary) {
return '看纪录片'
}
}
console.log('getHobby(1)', getHobby(1));