spacer

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

home / experts / javascript / column33


Call By Reference and Call By String

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Version 4.0 of DOCJSLIB introduces many functions that expect the DHTML element to be passed by reference. What this means is that the object itself should pass to the appropriate function. This is in contrary to the older functions in DOCJSLIB that expect object ID to be passed as a string. You can check if the element is passed by reference or by string, by simply printing it to an alert box. The object passed by reference will be printed as an object, while the one passed by string will be printed as a string. Objects are created in JavaScript in various ways. A common one is to use the new Layer() command.

Let's take an example that shows the differences between call-by-reference and call-by-string. The function setVisibility() sets the visibility of a passed-by-string element:

function docjslib_setVisibility(id, flag) {
  if (NS4) {
    var str = (flag) ? 'show' : 'hide';
    eval("document." + id).visibility = str;
  }
  else {
    var str = (flag) ? 'visible' : 'hidden';
    eval("document.all." + id).style.visibility = str;
  }
}

The following function sets the visibility of elements that are passed by reference (objects):

function docjslib_setElementVisibility(id, flag) {
  if (NS4) {
    var str = (flag) ? 'show' : 'hide';
    eval(id).visibility = str;
  }
  else {
    var str = (flag) ? 'visible' : 'hidden';
    eval(id).style.visibility = str;
  }
}

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: January 4, 1999
Revised: January 4, 1999

URL: http://www.webreference.com/js/column33/callmodes.html