博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TS4
阅读量:4455 次
发布时间:2019-06-07

本文共 1649 字,大约阅读时间需要 5 分钟。

类:类与对象字面量和接口差不多,比较两个类类型的对象时,只有实例的成员会被比较。 静态成员和构造函数不在比较的范围内。class Animal {    feet: number;    constructor(name: string, numFeet: number) {}}class Size {    feet: number;    constructor(numFeet: number) { }}let a: Animal = new Size(1); //冒号后面仅仅只是检验属性是不是一样的,不是类型let s: Size = new Animal("",0);function creat(x:Animal){} //冒号只是检验属性,不做类型检查,creat(a);creat(s);console.log(a);//Size {}console.log(s);//Animal {}-----------------------------------------------------------交叉类型:class A{    constructor(public _a1:number,public _a2:number){        this._a1 = _a1;        this._a2 = _a2;    }    fa1(){}}interface b{    b1:number;    f1();}class B implements b{    b1:number;    f1(){        console.log("f1");    }    fb1(){}    constructor(b1:number,public _B1:number,public _B2:number){        this.b1 = b1;        this._B1 = _B1;        this._B2 = _B2;    }}var a = new A(0,2);a._a1 = 1;var b = new B(3,4,5);console.log(a);for(let i in a){    console.log(i + "--" + typeof i);}console.log(b);for(let i in b){    console.log(i + "----" + typeof i);}var result;function extend
(a : T, b : U): T & U { result =
{}; for(let i in a){ //(
result)[i] = (
a)[i]; //result[i] = a[i]; (
result)[i] = (
a)[i]; } for(let i in b){ if(!result.hasOwnProperty(i)){ // (
result)[i] = (
b)[i]; result[i] = b[i]; (
result)[i] = (
b)[i]; } } return result;}extend(a,b);console.log("-----------------");console.log(result);for(let i in result){ console.log(i + "----" + typeof i);}

 

转载于:https://www.cnblogs.com/yaowen/p/7227304.html

你可能感兴趣的文章
用MySQL的存储过程来实现一些经典函数
查看>>
React (2) -- State and Lifecycle
查看>>
【转】在EmEditor上编译并运行JAVA
查看>>
关于SqlDateTime溢出的问题
查看>>
jquery下php与ajax的数据交换方式
查看>>
魅蓝Note有几种颜色 魅蓝Note哪个颜色好看
查看>>
使用PullToRefresh实现下拉刷新和上拉加载
查看>>
透明度百分比与十六进制转换
查看>>
HBase表预分区
查看>>
arcgis desktop 10.1 license manager无法启动问题解决
查看>>
django select_related() 联表查询
查看>>
mysql 常用,使用经验
查看>>
NSBundle,UIImage,UIButton的使用
查看>>
vue-cli3 中console.log报错
查看>>
GridView 中Item项居中显示
查看>>
UML类图五种关系与代码的对应关系
查看>>
如何理解作用域
查看>>
从无到满意offer,你需要知道的那些事
查看>>
P1516 青蛙的约会 洛谷
查看>>
SDOI2011 染色
查看>>