Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image prototype onload

 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm screwin' around to deepen my understanding of javascript OOP and event handling sorts of things. Recently, I've been beating image loading to death. No particular reason behind the specific way I want to do things, other than to learn about it.

I've been creating image objects in a loop and setting the onload attribute on each instance. It occurred to me that I should be able to set it for the Image object instead:


but I couldn't. "'Image.prototype' is null or not an object" At this point I am assuming that onload event handler cannot be added directly to the Image() object.

I started wondering then whether I could create an object based on Image() that would allow it's onload property to be set; something like:


I've thought about creating a whole new object with this.oImg = new Image() and an onload property in it, but ... that's for another exercise. This time around, I just want to know if it's possible to do something like what's described above.
[ April 22, 2007: Message edited by: Roger F. Gay ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently the Image class is a wrapper around a native object rather than a pure Javascript object like String. As such, the ability to manipulate it is signficantly curtailed.

This makes it a poor choice for a study on OOP in Javascript.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. I think I'll leave it alone, based on your comment. I can't help but think in practical terms anyway sometimes, even when I'm trying to go off on strange tangents for the learning experience -- and it has been getting a little difficult to feel that this is an interesing problem, given the minor impact (if any) that it would have on the actual functioning of what I've built.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Apparently the Image class is a wrapper around a native object rather than a pure Javascript object like String. As such, the ability to manipulate it is signficantly curtailed.

This makes it a poor choice for a study on OOP in Javascript.


And BTW, I did learn something along the way. Thanks again.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A solution was given that works in some browsers:

http://www.tek-tips.com/viewthread.cfm?qid=1359301
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic