2

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?

asked Apr 14, 2011 at 21:54
2
  • OK, I thought of a new one. canvas.image1 = global.factory(data1); Is that better than new? Commented Apr 16, 2011 at 16:08
  • canvas.image1 = global.factory(data1); Commented Apr 16, 2011 at 16:09

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.