typescript - 如何获得对象类实例?

Nat*_*isi 2 javascript inheritance typescript

我有一个类classA的对象,它继承自类classB

我的问题是:我怎么知道我的对象是否继承自classB

我试过: 对象instanceof classB

但它不起作用!

当我正在获取任何ts文件的实例时

0x800a138f - Microsoft JScript运行时错误:无法获取属性"prototype"的值:object为null或undefined

var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype; //exception occurs in this line
    d.prototype = new __();
};
Run Code Online (Sandbox Code Playgroud)

Jud*_*her 5

导致此类错误的一个原因是,您派生的类是在文件中的派生类之后.

这(以扼杀Ryan的回答):

class B extends A {
}

class A {
}

var x = new B();
console.log(x instanceof A); // Error
Run Code Online (Sandbox Code Playgroud)

...导致您在Playground中描述的错误.

我认为在codeplex上已有一个工作项,但是已经很晚了,我还没有检查过...