OOP: adding Event to an Javascript object
I want to add an eventlisterer 'click' to an object, which is represented to the user as image. This wouldn't work, but shows what i want to achieve:
function object {
this.picture = null;
this.src = 'images/defualt.png';
this.id = 1;
this.setImage(this.src);
}
object.prototype.setImage = function(src) {
this.picture = new Image();
this.picture.src = src;
this.picture.addEvenListener('click' , clickme, false);
}
clickme = function() {
alert('hurray, i'm clicked...');
}
|