如何检查一个类是否继承另一个(没有实例化一个对象)? [英] How to check if a class inherits another (without instanciating an object)?
本文介绍了如何检查一个类是否继承另一个(没有实例化一个对象)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function A(){}
function B(){}
B.prototype = new A();
如何检查类B是否在Javascript中继承了类A?
How can I check if the class B inherits class A in Javascript ?
(我想避免使用instanceof new B()instanceof A
)
(I would like to avoid instanciating B to use instanceof new B() instanceof A
)
推荐答案
尝试 B.prototype instanceof A
这篇关于如何检查一个类是否继承另一个(没有实例化一个对象)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文