When new keyword is missing, unhelpful error is thrown
chadsaun opened this issue · comments
Chad Saunders commented
When this line of code is called...
var ctx = C2S(304.797, 26.109);
... then it gets the error...
Cannot set property 'width' of undefined
When I set a breakpoint in canvas2svg on line 196 in Chrome, sure enough "this" is undefined.
Sometimes if I step through it slowly enough though, "this" will be "Window". And even in that circumstance, I get this error...
Object [object global] has no method '__setDefaultStyles'
on line 202...
this.__setDefaultStyles();
Kerry Liu commented
Chad Saunders commented
Ah yes, that seems to have fixed that. Thank you!
Kerry Liu commented
This is now fixed in v1.0.1 When C2S is called as a function (without new) this will correctly return a new C2S object. Please be aware that I've updated the signature to export to svg for ease of use and easier debugging (won't happen again in the future). So: ctx.toString() is now:
var ctx = new C2S({width:200, height:300});
ctx.fillRect(0,0,100,100);
//etc
ctx.getSerializedSvg(true); //serialized svg (if true is passed convert named entities to numbed entities)
ctx.getSvg();//inline svg