faqts : Computers : Programming : Languages : JavaScript : Language Core : prototypes/inheritance

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 14 people (71%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Can someone give me a working example of a class that inherits the properties of the built in Image Ojbect?

Jan 17th, 2001 14:36
Mike Moretti, Hayden Porter,


function ImageSubClass() {
   this.extraproperty = 1;
}

// Subclass Image
ImageSubClass.prototype = new Image();
// Now let's add a function for the subclass
ImageSubClass.prototype.getExtraProperty = function() { return
(this.extraproperty); };

// Now you can create a new ImageSubClass and it will have all
// properties of Image as well as ImageSubClass
var isc = new ImageSubClass();
isc.src = "somegiffile.gif";
alert(isc.getExtraProperty() + " " + isc.width);