Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2: Browser-Dependent Subclass - Doc JavaScript
Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2
Browser-Dependent Subclass
You have to define a subclass for each different browser that you want to support. The first action you need to do when defining a subclass is to inherit the properties and the methods of its superclass. You first assign the name of the superclass creation function to a dummy method, inheritFrom
:
this.inheritFrom = docjslibSuperClass;
And then you call this method:
this.inheritFrom();
By now, the subclass inherited the superclass' methods and properties. Now, it's time to define the browser-dependent methods and properties. Generally speaking, you you should also override the superclass' methods and properties if needed. In our case, we just add methods to the subclass. We first assign function names to the methods:
this.getSrc = getSrcMethod;
this.setSrc = setSrcMethod;
And then define the functions:
function getSrcMethod(id) {
return eval("document.all." + id + "img.src");
}
function setSrcMethod(id, url) {
eval("document.all." + id + "img").src = url;
}
We show here excerpts from the IE4 subclass. Here is its full listing:
function docjslibIE4SubClass() {
this.inheritFrom = docjslibSuperClass;
this.inheritFrom();
this.getSrc = getSrcMethod;
this.setSrc = setSrcMethod;
function getSrcMethod(id) {
return eval("document.all." + id + "img.src");
}
function setSrcMethod(id, url) {
eval("document.all." + id + "img").src = url;
}
}
Similar subclasses are defined for IE5, NS4, and NS6. See listing of all classes later in this column.
Next: How to write an application using DOCJSLIB 1.2
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 12, 2001
Revised: February 12, 2001
URL: https://www.webreference.com/js/column77/8.html