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?
-
OK, I thought of a new one. canvas.image1 = global.factory(data1); Is that better than new?Jim Rootham– Jim Rootham2011年04月16日 16:08:42 +00:00Commented Apr 16, 2011 at 16:08
-
canvas.image1 = global.factory(data1);Jim Rootham– Jim Rootham2011年04月16日 16:09:24 +00:00Commented Apr 16, 2011 at 16:09
1 Answer 1
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.
answered Apr 14, 2011 at 21:57
Joost Diepenmaat
17.8k3 gold badges48 silver badges55 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js