如何确定两个对象是否属于同一类型(即同一类)?这些对象可以是大约 20 个不同类中的任何一个,所以我不想进行巨大的测试,无论是 A 实例,还是 B 实例,...但是打字稿中没有 GetType()/getClass() 。
谢谢-戴夫
只需使用该 constructor 属性即可。参考: http: //basarat.github.io/this-and-prototype/#/reflection
class Animal {}
class Bird extends Animal {}
var animal = new Animal();
var bird = new Bird();
console.log(animal.constructor == Animal); // true
console.log(bird.constructor == Bird); // true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3852 次 |
| 最近记录: |