- 只会比较
实例成员
class Person {
public name: string;
}
class Animal {
public name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;
- 只能将
多
的属性赋值给少
的,不可将少
的属性赋值给多
的
class Person {
public name: string;
public age: number;
}
class Animal {
public name: string;
}
let p: Person;
let a: Animal;
// 多????少
a = p;
// 少????多
p = a;
- 不会比较类的
构造函数
和静态成员
class Person {
public name: string;
public static age: number;
constructor(name: string, age: number) {
}
}
class Animal {
public name: string;
constructor(name: string, age: number) {
}
}
let p: Person;
let a: Animal;
a = p;
p = a;
类的私有属性和受保护属性会响应兼容性
私有属性:
class Person {
private name: string;
}
class Animal {
private name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;
受保护属性:
class Person {
protected name: string;
}
class Animal {
protected name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;