I'm using the svg.js library.
How can we check if a variable x
is an instance of SVG
class?
I tried:
new SVG(document.createDocumentFragment()) instanceof SVG // false
new SVG(document.createDocumentFragment()).contructor === SVG // false
I'm using the svg.js library.
How can we check if a variable x
is an instance of SVG
class?
I tried:
new SVG(document.createDocumentFragment()) instanceof SVG // false
new SVG(document.createDocumentFragment()).contructor === SVG // false
Checking what value SVG
function returns we find that a new element
is created and returned. It is an instance of SVG.Doc
:
> SVG
svg.js:12 function (element) {
if (SVG.supported) {
element = new SVG.Doc(element)
if (!SVG.parser)
SVG.prepare(element)
return element
}
}
So, the solution is:
new SVG(document.createDocumentFragment()) instanceof SVG.Doc // true
// or using the x variable
var x = new SVG(document.createDocumentFragment());
x instanceof SVG.Doc // true