Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When new keyword is missing, unhelpful error is thrown #2

Closed
chadsaun opened this issue Feb 10, 2014 · 3 comments
Closed

When new keyword is missing, unhelpful error is thrown #2

chadsaun opened this issue Feb 10, 2014 · 3 comments
Labels

Comments

@chadsaun
Copy link

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();
@gwwar
Copy link
Contributor

gwwar commented Feb 10, 2014

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.

@chadsaun
Copy link
Author

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

@gwwar gwwar added bug and removed bug labels Feb 10, 2014
@gwwar
Copy link
Contributor

gwwar commented Feb 16, 2014

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

@gwwar gwwar closed this as completed Feb 16, 2014
x4d3 pushed a commit to x4d3/canvas2svg that referenced this issue Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants