簡體   English   中英

檢查變量是否為SVG.js元素實例

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM