spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column77


Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Creating a Class on the Fly

The function createTheProperSubClass() creates on the fly the proper browser-dependent object. The function actually defines a class with one property, className, and one method, getTheProperSubClass. The property className depends on the browser type:

var browserType = new browserSniffer();
  if (browserType.ie4) {
    this.className = "docjslibIE4SubClass";
  }
  else if (browserType.ie5) {
    this.className = "docjslibIE5SubClass";
  }
  else if (browserType.ns4) {
    this.className = "docjslibNS4SubClass";
  }
  else if (browserType.ns6) {
    this.className = "docjslibNS6SubClass";
  }

We then define the method getTheProperSubClass():

this.getTheProperSubClass = getTheProperSubClassMethod;
  
  function getTheProperSubClassMethod() {
    // example: return new docjslibIE5SubClass();
	return eval('new ' + this.className + '()');
  }

Notice that the ultimate impact of createTheProperSubClass() function is to generate a string for a new object. For IE5, it should be:

new docjslibIE5SubClass();

For NS6, it should be:

new docjslibNS6SubClass();

We'll show you later in this column how to assign a variable name to this new object.

Next: How to write a browser-independent superclass

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 12, 2001
Revised: February 12, 2001

URL: http://www.webreference.com/js/column77/6.html