The example you sent me is exactly what I coded. The Person function is my
collection and setName function is my Map. The difference is that you don't
need to know the names of your properties to get them back out and you can
choose to output them as an array or a list.

-----Original Message-----
From: Ron Hornbaker [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 01, 2002 1:38 PM
To: [EMAIL PROTECTED]
Subject: RE: [KCFusion] Client side variable storage


Bryan,

Nice code. Just curious: what's the advantage of this over using
JavaScript's built-in custom oop features, available in v4 and higher
browsers? It would likely be simpler:

http://developer.netscape.com/evangelism/docs/articles/oop-javascript/

-Ron

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Bryan LaPlante
> Sent: Tuesday, April 30, 2002 8:59 PM
> To: KCFusion
> Subject: [KCFusion] Client side variable storage
>
>
> Hey all,
> I was messing around today and got to thinking how tired I am
> of the limited
> storage capability on the clients browser. I wrote this little
> script that
> will store name value pairs like a collection in cf only on the
> client side.
> I called the file pasted below collection.js and if you have ever used
> HashMap in Java you will see the similarity. If any one can use
> this here it
> is.
>
> /*
> Collection.js
>
> AUTHOR:
>  Bryan LaPlante
>  [EMAIL PROTECTED]
>  Network Web Applications
>  http://www.netwebapps.com
>
> DESCRIPTION: Collection
> creates a new collection of name=value pairs and provides methods for
> retrieving one or a list of keys or values.
>
> CREATE A COLLECTION:
>  myCollection = new Collection();
>
> METHODS
>  myCollection.clear(); // Removes all of the key value pairs
> but does not
> destroy the collection.
>  myCollection.put(key,value); //Creates an entry into the collection
>  myCollection.getValue(key); // does a case sensitive search
> for a key in
> the collection and returns it's value
>  myCollection.getValueNoCase(key); // does a case insensitive
> search for a
> key in the collection and returns it's value
>  myCollection.getKeyArray(); //returns an array of keys
>  myCollection.getValueArray(); // returns an array of values
>  myCollection.getKeyList(delim); //returns a list of keys
>  myCollection.getValueList(delim); // returns a list of values
>
> EXAMPLE:
>  Un comment the code at the bottom of the script to see
>  an example of how to use the collection.
> */
>
>  function Map(key,val){
>   this.key = key;
>   this.val = val;
>  }
>
>  function Collection(){
>   this.collectionMap = new Array();
>   this.clear = clearMap;
>   this.put = putMap;
>   this.getValue = getValue;
>   this.getValueNoCase = getValueNoCase;
>   this.getKeyArray = getKeyArray;
>   this.getValueArray = getValueArray;
>   this.getKeyList = getKeyList;
>   this.getValueList = getValueList;
>  }
>
>  function putMap(key,val){
>   existingKeys = this.getKeyArray();
>   isUniqueKey = true;
>
>   for(i=0; i<existingKeys.length; i++){
>    if(existingKeys[i] == key){
>     isUniqueKey = false;
>     this.collectionMap[i].val=val;
>     break;
>    }
>   }
>
>   if(isUniqueKey){
>    this.collectionMap[this.collectionMap.length]= new Map(key,val);
>   }
>  }
>
>  function clearMap(){
>   this.collectionMap.length=0;
>  }
>
>  function getValue(key){
>   for(i=0; i<this.collectionMap.length; i++){
>    if(this.collectionMap[i].key == key){
>     return this.collectionMap[i].val;
>    }
>   }
>   return null;
>  }
>
>  function getValueNoCase(key){
>   for(i=0; i<this.collectionMap.length; i++){
>    if(this.collectionMap[i].key.toLowerCase() == key.toLowerCase()){
>     return this.collectionMap[i].val;
>    }
>   }
>   return null;
>  }
>
>  function getKeyArray(){
>   keyArray = new Array();
>   for(i=0; i<this.collectionMap.length; i++){
>    keyArray[keyArray.length]=this.collectionMap[i].key;
>   }
>   return keyArray;
>  }
>
>  function getKeyList(delim){
>   keyList = "";
>   for(i=0; i<this.collectionMap.length; i++){
>    if(i == this.collectionMap.length-1){
>     delim="";
>    }
>    keyList += (this.collectionMap[i].key + delim);
>   }
>   return keyList;
>  }
>
>  function getValueArray(){
>   valueArray = new Array();
>   for(i=0; i<this.collectionMap.length; i++){
>    valueArray[valueArray.length]=this.collectionMap[i].val;
>   }
>   return valueArray;
>  }
>
>  function getValueList(delim){
>   valueList = "";
>   for(i=0; i<this.collectionMap.length; i++){
>    if(i == this.collectionMap.length-1){
>     delim="";
>    }
>    valueList += (this.collectionMap[i].val + delim);
>   }
>   return valueList;
>  }
>  /*
>  /////------- Uncomment this section for
> testing --------///////////////////////
>
>  //create the collection
>  collection = new Collection();
>
>  // clear the collection
>  collection.clear();
>
>  // add name value pairs to the collection
>  collection.put("bryan","user1");
>  collection.put("bruce","user2");
>  collection.put("dan","user3");
>
>  // putting bryan again will update the previous entry's value to user4
>  collection.put("bryan","user4");
>
>  alert(collection.getKeyList(","));
>  alert(collection.getValueList("|"));
>  // get an array of keys
>  myKeys = collection.getKeyArray();
>
>  // get an array of values
>  myVals = collection.getValueArray();
>
>  //Output the names and their values into an html list item
>  document.write("<ul>");
>  for(c=0; c<myKeys.length; c++){
>   document.write("<li>" + myKeys[c].toString() +"=" +
> myVals[c].toString());
>  }
>  document.write("<ul>");
>  */
>
>
> Bryan LaPlante
> President
> Network Web Applications Inc.
>
>
>
> ______________________________________________________________________
> The KCFusion.org list and website is hosted by Humankind Systems, Inc.
> List Archives........ http://www.mail-archive.com/cf-list@kcfusion.org
> Questions, Comments or Glowing Praise.. mailto:[EMAIL PROTECTED]
> To Subscribe.................... mailto:[EMAIL PROTECTED]
> To Unsubscribe................ mailto:[EMAIL PROTECTED]
>

 
 
______________________________________________________________________
The KCFusion.org list and website is hosted by Humankind Systems, Inc.
List Archives........ http://www.mail-archive.com/cf-list@kcfusion.org
Questions, Comments or Glowing Praise.. mailto:[EMAIL PROTECTED]
To Subscribe.................... mailto:[EMAIL PROTECTED]
To Unsubscribe................ mailto:[EMAIL PROTECTED]
 
 
 
______________________________________________________________________
The KCFusion.org list and website is hosted by Humankind Systems, Inc.
List Archives........ http://www.mail-archive.com/cf-list@kcfusion.org
Questions, Comments or Glowing Praise.. mailto:[EMAIL PROTECTED]
To Subscribe.................... mailto:[EMAIL PROTECTED]
To Unsubscribe................ mailto:[EMAIL PROTECTED]
 

Reply via email to