Image Prototype Method is not Recognized

Hi,

I’m trying to add a prototype method to the Image object, but I always get the error “images[i].getSize() is not a function”. Why?

Here is the relevant code:

                       
Image.prototype.getSize = function() {
  ... 
};


function getImages(obj) {
  var jsonData = obj.data;
  ...
  images = new Array();
                                              
  for (var i = 0; i < jsonData.images.length; i++) {
    images[i] = new Image();
    images[i].src = jsonData.images[i].url;     
    images[i].getSize();
  }                                        
}  

Thx.

The Image object is not a part of the official javascript objects, so you can’t extend it like other objects.

Image is more of a browser-based wrapper, than a real object in its own right.