7、Typescript 数组接口、类接口
作者:
圆梦人生 | 来源:发表于
2019-03-06 10:34 被阅读1次案例
// 1、数组接口
interface ArrayInterface {
// 索引index是必须的
[index:number]:string;
}
let arrayInfo:ArrayInterface = ['a', 'b', 'c'];
console.log(arrayInfo);
// 2、定义接口
interface ClassInterface {
// 定义方法
showInfo(str:string):any
}
class ClasOne implements ClassInterface {
// 实现接口方法
showInfo(str:string){
console.log('ClasOne====' + str);
}
}
class ClassTwo implements ClassInterface {
// 实现接口方法
showInfo(str:string){
console.log('ClassTwo====' + str);
}
}
let c1 = new ClasOne();
c1.showInfo('zs');
let c2 = new ClassTwo();
c2.showInfo('lis');
本文标题:7、Typescript 数组接口、类接口
本文链接:https://www.haomeiwen.com/subject/gtttpqtx.html
网友评论