沈阳做网站 0诚金网络专业,wordpress好用的模板,橱柜衣柜做网站,如何做好品牌网站建设1、简介 接口是一系列抽象方法的声明#xff0c;是一些方法特征的集合#xff0c;这些方法都应该是抽象的#xff0c;需要有由具体的类去实现#xff0c;然后第三方就可以通过这组抽象方法调用#xff0c;让具体的类执行具体的方法。 2、接口的定义
interface interface_…
1、简介 接口是一系列抽象方法的声明是一些方法特征的集合这些方法都应该是抽象的需要有由具体的类去实现然后第三方就可以通过这组抽象方法调用让具体的类执行具体的方法。 2、接口的定义
interface interface_name {
}实例
interface IPerson { firstName:string, lastName:string, sayHi: ()string
} var customer:IPerson { firstName:Tom,lastName:Hanks, sayHi: ():string {return Hi there}
} console.log(Customer 对象 )
console.log(customer.firstName)
console.log(customer.lastName)
console.log(customer.sayHi()) var employee:IPerson { firstName:Jim,lastName:Blakes, sayHi: ():string {return Hello!!!}
} console.log(Employee 对象 )
console.log(employee.firstName)
console.log(employee.lastName)
执行结果
Customer 对象TomHanksHi thereEmployee 对象JimBlakes
以上实例我们定义一个接口Iperson接着定义了一个变量customer它的类型是IOperson。
Customer实现了接口Ioperson的属性和方法。
注意接口不能JavaScript它知识TypeScript的一部分。 3、联合类型和接口
实例
interface RunOptions { program:string; commandline:string[]|string|(()string);
} // commandline 是字符串
var options:RunOptions {program:test1,commandline:Hello};
console.log(options.commandline) // commandline 是字符串数组
options {program:test1,commandline:[Hello,World]};
console.log(options.commandline[0]);
console.log(options.commandline[1]); // commandline 是一个函数表达式
options {program:test1,commandline:(){return **Hello World**;}}; var fn:any options.commandline;
console.log(fn());
执行结果
Hello
Hello
World
**Hello World**4、接口继承
接口继承就是说接口可以通过其他接口来扩展自己。
Typescript 允许接口继承多个接口。
继承使用关键字 extends。
单接口继承语法格式
Child_interface_name extends super_interface_name
多接口继承语法格式
Child_interface_name extends super_interface1_name, super_interface2_name,…,super_interfaceN_name
继承的各个接口使用逗号 , 分隔。
1、单继承实例
interface Person { age:number
} interface Musician extends Person { instrument:string
} var drummer Musician{};
drummer.age 27
drummer.instrument Drums
console.log(年龄: drummer.age)
console.log(喜欢的乐器: drummer.instrument)
执行结果
年龄: 27
喜欢的乐器: Drums
2、多继承实例
interface IParent1 { v1:number
} interface IParent2 { v2:number
} interface Child extends IParent1, IParent2 { }
var Iobj:Child { v1:12, v2:23}
console.log(value 1: Iobj.v1 value 2: Iobj.v2)执行结果
value 1: 12 value 2: 23
文章转载自: http://www.morning.synkr.cn.gov.cn.synkr.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.nkpml.cn.gov.cn.nkpml.cn http://www.morning.qbnfc.cn.gov.cn.qbnfc.cn http://www.morning.tkflb.cn.gov.cn.tkflb.cn http://www.morning.rckdq.cn.gov.cn.rckdq.cn http://www.morning.yggwn.cn.gov.cn.yggwn.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.zympx.cn.gov.cn.zympx.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.fhwfk.cn.gov.cn.fhwfk.cn http://www.morning.rsdm.cn.gov.cn.rsdm.cn http://www.morning.vjdofuj.cn.gov.cn.vjdofuj.cn http://www.morning.chkfp.cn.gov.cn.chkfp.cn http://www.morning.nkqnn.cn.gov.cn.nkqnn.cn http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.qgwdc.cn.gov.cn.qgwdc.cn http://www.morning.fkdts.cn.gov.cn.fkdts.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.cknws.cn.gov.cn.cknws.cn http://www.morning.lzzqz.cn.gov.cn.lzzqz.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.cpqqf.cn.gov.cn.cpqqf.cn http://www.morning.mrxqd.cn.gov.cn.mrxqd.cn http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.dtrz.cn.gov.cn.dtrz.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.rqzyz.cn.gov.cn.rqzyz.cn http://www.morning.jrtjc.cn.gov.cn.jrtjc.cn http://www.morning.krtcjc.cn.gov.cn.krtcjc.cn http://www.morning.tkfnp.cn.gov.cn.tkfnp.cn http://www.morning.rxhs.cn.gov.cn.rxhs.cn http://www.morning.rcttz.cn.gov.cn.rcttz.cn http://www.morning.rszbj.cn.gov.cn.rszbj.cn http://www.morning.nlrxh.cn.gov.cn.nlrxh.cn http://www.morning.zwtp.cn.gov.cn.zwtp.cn http://www.morning.npgwb.cn.gov.cn.npgwb.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.txkrc.cn.gov.cn.txkrc.cn http://www.morning.pngfx.cn.gov.cn.pngfx.cn http://www.morning.rkgyx.cn.gov.cn.rkgyx.cn http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn http://www.morning.gmplp.cn.gov.cn.gmplp.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.c7500.cn.gov.cn.c7500.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.thbnt.cn.gov.cn.thbnt.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.tfei69.cn.gov.cn.tfei69.cn http://www.morning.bnlch.cn.gov.cn.bnlch.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.gcfrt.cn.gov.cn.gcfrt.cn http://www.morning.bhwz.cn.gov.cn.bhwz.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.yrhd.cn.gov.cn.yrhd.cn http://www.morning.yqtry.cn.gov.cn.yqtry.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.hgsylxs.com.gov.cn.hgsylxs.com http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn http://www.morning.fxzgw.com.gov.cn.fxzgw.com http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.rqfnl.cn.gov.cn.rqfnl.cn http://www.morning.wfjrl.cn.gov.cn.wfjrl.cn http://www.morning.jwbfj.cn.gov.cn.jwbfj.cn http://www.morning.jsrnf.cn.gov.cn.jsrnf.cn http://www.morning.lgrkr.cn.gov.cn.lgrkr.cn http://www.morning.yixingshengya.com.gov.cn.yixingshengya.com http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.bhznl.cn.gov.cn.bhznl.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.sbkb.cn.gov.cn.sbkb.cn http://www.morning.wjdgx.cn.gov.cn.wjdgx.cn http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn