我正在使用svg.js库。
我们如何检查变量x
是否是SVG
类的实例?
我试过了:
new SVG(document.createDocumentFragment()) instanceof SVG // false
new SVG(document.createDocumentFragment()).contructor === SVG // false
答案 0 :(得分:0)
检查SVG
函数返回的值,我们发现创建并返回了新的element
。它是SVG.Doc
:
> SVG
svg.js:12 function (element) {
if (SVG.supported) {
element = new SVG.Doc(element)
if (!SVG.parser)
SVG.prepare(element)
return element
}
}
所以,解决方案是:
new SVG(document.createDocumentFragment()) instanceof SVG.Doc // true
// or using the x variable
var x = new SVG(document.createDocumentFragment());
x instanceof SVG.Doc // true