Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个随机的 DOM 节点,我想确定它是否是一个svg元素,即从SVGElement构造函数继承。我知道我可以通过调用__proto__节点来遍历原型链,但是是否有内置方法来确定这一点?
svg
SVGElement
__proto__
有一个专门的instanceof操作符检查一个对象的原型链中是否有构造函数的原型:
instanceof
node instanceof SVGElement
但是,鉴于您实际上不能这样做new SVGElement()(与所有节点构造函数一样),这可能无法在所有浏览器中可靠地工作。
new SVGElement()