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);
开发者_JAVA百科
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?
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.
精彩评论