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
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

Browser-Independent Superclass

The superclass of DOCJSLIB 1.2 includes a single method, makeImage. This method is common to all browsers, so there is no need to duplicate this method in all browser-dependent subclasses. All subclasses inherit their superclass' methods. In our case, they all inherit this single method, makeImage. They don't need, of course, to override it, because it is browser-independent. To define a method of an object, you first assign its name to a function name:

this.makeImage = makeImageMethod;

Notice that the method name, makeImage, does not necessarily need to be identical to the function name, makeImageMethod. You then have to define the function:

function makeImageMethod(imgID,  // given id
               imgURL,       // image URL
               imgHeight,    // image height
               imgWidth,     // image width
               imgAlt,       // alternative image
               posFromLeft,  // absolute position from left of window
               posFromTop,   // absolute position from top of window
               clickParam1,  // parameter passed to "onclick" handler
               clickParam2)  // parameter passed to "onclick" handler
  {
    document.write(
    '<STYLE TYPE="text/css">',
    '#', imgID, ' {',
      'position: absolute;',
      'left: ', posFromLeft, ';',
      'top: ', posFromTop, ';',
      'width: ', imgWidth, ';',
      'z-index: 1',
    '}',
    '</STYLE>',
    '<DIV ID="', imgID, '">',
    '<A HREF="javascript:', "handleImageClick('", imgID, "'", ',',
    clickParam1, ',', clickParam2, ')">',
    '<IMG NAME="', imgID, 'img" ID="', imgID, 'img" SRC="', imgURL,
    '" ALT="', imgAlt, '" BORDER="0" ', 'HEIGHT="', imgHeight,
    '" WIDTH="', imgWidth, '">', '</A></DIV>'
    );
  }

Next: How to write a browser-dependent subclass

http://www.internet.com


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


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/7.html