当前位置: 首页 > news >正文

ps个人网站西安至成信息科技有限公司

ps个人网站,西安至成信息科技有限公司,编辑网站用什么软件,个人电脑做服务器网站接口是对类的一部分行为的抽象 类类型 实现接口 为什么不是描述类呢#xff1f;而是类一部分行为的抽象#xff1f; 类中分为#xff1a;静态部分#xff08;构造器#xff09;、实例部分#xff08;类成员#xff09;。 类成员#xff1a;实例的属性、原型上的方…接口是对类的一部分行为的抽象 类类型 实现接口 为什么不是描述类呢而是类一部分行为的抽象 类中分为静态部分构造器、实例部分类成员。 类成员实例的属性、原型上的方法。 接口就是为了修饰类成员。 静态部分constructor 构造函数是不能通过接口实现的接口实现的是构造函数实例化的对象。 类的本质是构造函数构造函数上没有类成员所以接口不能描述类而是说类实现的这个接口。 类实现的这个接口接口描述属性在类中去具体实现。 接口描述了类的公共部分 总结修饰类需要写两个接口 一个函数一个接口用来修饰类成员一个接口用来修饰类构造函数本身用一个函数把两者合并。 interface IPerson {name: string;sayName: (a: string) void; }interface IPersonCons {new (a: string): IPerson;hobby: string;sayHobby: (b: string) void; }class Person implements IPerson {name 123;sayName(c: string) {console.log(this.name, c);}constructor(a:string) {this.name a;};static hobby 123;static sayHobby (b: string){console.log(this.hobby, b);} }function createPerson(c:IPersonCons): IPerson{return new c(zhangsan); }let person createPerson(Person); console.log(person.name); //zhangsanperson.sayName(white); //zhangsan white person.sayName(white); //zhangsan whiteconsole.log(Person.hobby); //123 Person.sayHobby(baskstball); //123 baskstball如果没有静态属性函数可以怎么写 interface IPerson {name: string;sayName: (a: string) void;//简写上面:sayName(); } class Person implements IPerson {name 123;sayName(c: string) {console.log(this.name, c);}constructor(a:string) {this.name a;}; } //写法1 function createPerson(c:{new (a: string): IPerson;}): IPerson{return new c(zhangsan); } //写法2 function createPerson(c:new (a: string) IPerson): IPerson{return new c(zhangsan); } //写法3 // 抽象泛型,T可以理解为一个泛型变量属于类型变量这里属于IPerson接口继承接口实现接口的抽象 function createPerson T extends IPerson(c:new (a: string) T): T{return new c(zhangsan); }注意两个ts配置 strictNullChecks: true, /* When type checking, take into account null and undefined. */ strictPropertyInitialization: true, /* Check for class properties that are declared but not set in the constructor. */接口继承接口 接口继承接口相当于接口的拓展。 interface Shape {color: string; }interface Square extends Shape {sideLength: number; }let a:Square {color: white,sideLength: 60 }一个接口可以继承多个接口创建出多个接口的合成接口。 interface Shape {color: string; }interface PenStroke {penWidth: number; }interface Square extends Shape, PenStroke{sideLength: number; }let a:Square {color: white,sideLength: 60,penWidth: 30 }type是类型别名给交叉类型赋别名 type ShapeAndPenStroke Shape PenStroke interface Square1 extends ShapeAndPenStroke{sideLength: number; }交叉类型两个都包括Shape PenStroke 联合类型两个取其一Shape | PenStroke 类型断言 清楚地知道一个实体的类型在赋值时人为确定类型不需要ts进行类型推断。 两种写法 值as类型 类型值 interface Shape {color: string; }interface PenStroke {penWidth: number; }interface Square extends Shape, PenStroke {sideLength: number; }// let square Square{}; let square {} as Square; square.color blue; square.sideLength 10; square.penWidth 5.0;混合类型 混合类型一个接口中有函数、有属性 interface Counter {(start: number): string;interval: number;reset(): void; }function getCounter(): Counter {let counter Counterfunction (start: number) { };counter.interval 123;counter.reset function () { };return counter; }let c getCounter(); c(10); c.reset(); c.interval 5.0;
http://www.w-s-a.com/news/977664/

相关文章:

  • 网站认证必须做么cc0图片素材网站
  • net域名 著名网站国外设计案例网站
  • 淘宝客网站哪里可以做app地推网
  • 宜昌建设厅网站中国最新时事新闻
  • 微网站怎么开发wordpress 发表评论
  • 山东网站建设是什么一页网站首页图如何做
  • 游戏开发与网站开发哪个难万网影
  • 做网站编程语言建筑施工特种证书查询
  • 找人做网站内容自己编辑吗修改wordpress登陆界面
  • 登陆建设银行wap网站湖南网站建设磐石网络答疑
  • 58网站怎么做浏览度才高论坛网站怎么做排名
  • wordpress 手机网站支付京东网站建设的经费预算
  • 自己怎么样做游戏网站做海外贸易网站
  • 建立什么样的网站好制作网页网站代码
  • 岳麓区专业的建设网站公司尚一网常德论坛
  • 电商网站建设实训报告360站长平台链接提交
  • 个性化网站建设公司个人网站备案类型
  • 腾讯建站模板上海网站开发有限公司
  • 网站和小程序的区别请问做网站怎么赚钱
  • 网站logo设计免费版在线网站开发建设准备工作
  • wordpress多站点 主题南京做网站好的公司
  • 广州 门户seo到底是做什么的
  • 可以登录国外网站吗如何用家用电脑做网站
  • 吉安建站公司wordpress企业
  • 河北住房和城乡建设厅网站6thinkphp做视频网站
  • 遵义网站制作一般需要多少钱深圳全国网站制作哪个好
  • 公众平台网站价格哪个网站做餐饮推广最好
  • 深圳 公司网站设计重庆的网站设计公司价格
  • 网站开发市场分析餐饮平台app有哪些
  • 制作一个收费网站要多少钱开发网站需要什么技术