DOCJSLIB Version 4.0: Further Streamlining of the HTML Scroller - www.docjavascript.com
Call By Reference and Call By String
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;
}
}
Produced by Yehuda Shiran and Tomer Shiran
Created: January 4, 1999
Revised: January 4, 1999
URL: https://www.webreference.com/js/column33/callmodes.html