server-side JavaScript: Example 3: Dictionary class

G

GVDC

Example server-side JavaScript Web script, Dictionary class


//Dictionary class, hash array unlimited length configurable speed/efficiency
//
printf("<html><body>");

printf("<b>Creating dictionary</b><br\n>");

var dictobj = new Dictionary(5); //dictionary class
var dvname = "varnam0"; //dict var name

var smplobj = new Object(); //create object
smplobj.xx = "text1"; //add properties
smplobj.yy = "text2";

printf("<b>Storing object into dictionary</b><br\n>");
printf("<br\n>");
//put object into array
dictobj.set(dvname,smplobj);

printf("<b>Reading value stored in dictionary</b><br\n>");
printf("value of " ,dvname, " property xx: [", dictobj.get(dvname).xx, "]<br\n>");
printf("<br\n>");

printf("<b>Changing property xx value to otherval567</b><br\n>");

//values in dictionary are stored by reference, not copy
//modifying value of object's property also changes value stored in dictionary
smplobj.xx = "otherval567";

printf("value of " ,dvname, " property xx after change: [", dictobj.get(dvname).xx, "]<br\n>");
printf("<br\n>");


printf("<b>Checking array (dictionary) length</b><br\n>");
printf("array length: [", dictobj.len(), "]<br\n>");
printf("<br\n>");

printf("<b>Deleting value from array</b><br\n>");
//erase value from dictionary
dictobj.set(dvname,null);

printf("array length after delete: [", dictobj.len(), "]<br\n>");


printf("</body></html>");



--
 
T

Thomas 'PointedEars' Lahn

GVDC said:
Example server-side JavaScript Web script, Dictionary class

Example client-side JavaScript, complete Idiot "class":

function Idiot()
{
var value = "GVDC";
this.who = function() { return value; };
}

window.alert((new Idiot()).who());

<http://jibbering.com/faq/>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top