A类是否来自B类

时间:2015-01-21 14:18:30

标签: javascript

我想知道如何判断A类是否来自JavaScript中的B类。这是一个例子,为了清楚起见使用ES6类:

class Animal
{
}

class Dog extends Animal
{
}

class Cat extends Animal
{
}

// ...

function makeAnimalOf(ctor)
{
    if (/* ctor derived from Animal */) {
        return new ctor;
    }
    throw "ctor is not derived from Animal";
}

var mrWoofles = makeAnimalOf(Dog);
var mittens = makeAnimalOf(Cat);

makeAnimalOf中我的键控器需要看起来像什么?

0 个答案:

没有答案