Jim Rootham
Jim Rootham

Reputation: 61

Javascript design question

I am designing a page that has a canvas element which displays 2 images on it. I can see 3 ways to attach the data to the element.

1)

canvas.image1 = new ImageClass(data1);

2)

canvas.image1 = Image();
global.factory(canvas.image1, data1);

3)

canvas.image1 = 0;
global.factory(canvas.image1, data1);

Are there any other ways? Which one is better, and why?

Upvotes: 2

Views: 75

Answers (1)

Joost Diepenmaat
Joost Diepenmaat

Reputation: 17773

In the interest of clarity and bug-prevention, I prefer, if possible, to add elements to their parents only when they're fully initialized. So option 1 would seem to be the clearest and option 3 seems like the road to madness.

Of course, a Canvas element has no property image1, so setting it wouldn't do anything.

Upvotes: 1

Related Questions