SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code JavaScript:
    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.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •