gliffy / canvas2svg

Translates HTML5 Canvas draw commands to SVG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When new keyword is missing, unhelpful error is thrown

chadsaun opened this issue · comments

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();

Unless I'm mistaken you're missing the new keyword. So try:

var ctx = new C2S(304.797, 26.109);

screen shot 2014-02-10 at 11 41 37 am

I should add an explicit warning that you're missing the keyword. Thanks for the report.

Ah yes, that seems to have fixed that. Thank you!

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