[英]Check if the variable is a SVG.js element instance
我正在使用svg.js庫。
我們如何檢查變量x
是否是SVG
類的實例?
我試過了:
new SVG(document.createDocumentFragment()) instanceof SVG // false
new SVG(document.createDocumentFragment()).contructor === SVG // false
檢查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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.