Why does this Pair class not work as I expect
<p>My background is C++ where it seems working with objects is very different to Javascript.  C++ has a Pair object like the Pair below I am trying to re-create.  But this class does not work as I intended.  Perhaps it is totally the wrong approach for Javascript.  My ultimate aim is to parse a string of key1=val1;key2=val2;key3=val3; into an associative array.  So any tips on that would be helpful.  But my first problem is the Pair class below.  any help would be much appreciated.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;my title&lt;/title&gt;
&lt;script type="text/javascript"&gt;
//Pair class - doesnt seem to work
function Pair(key, value) {
    this.key = key;
    this.value = value;
}

Pair.prototype.Key = function() { return this.key; }
Pair.prototype.Value = function() { return this.value; }


function getValueAndKey(text, splitter) {
   //Pair pair = {};
   if(text) {
     var delim = typeof splitter !== 'undefined' ? splitter : '='; 
     var delimpos = text.indexOf(delim);
     if(delimpos != -1) {
          var strkey = text.substr(0, delimpos);
          var strvalue = text.substr(delimpos+1);
          return Pair(strkey, strvalue);      
     }      
   }
   return null;
}

function doIt() {

   function Options(sourceString) {
      this.source = sourceString;

      //populate key/value pairs from source string
      var vars_array = sourceString.split(";");
      for(var i = 0; i &lt; vars_array.length; ++i) {
         //alert("adding vars_array[" + i + "] = " + vars_array[i]);
         var pair = getValueAndKey(vars_array[i]);
         if(pair)  //pair is ALWAYS undefined :(
            alert("key=" + pair.Key() + " value=" + pair.Value());       
      }
   }

   //exercise class
   var sourceString = "cat=Cookie;legs=4;favouritefood=lamb;type=Siamese;";
   var opts = new Options(sourceString);
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body onload="doIt();"&gt;
some test program
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
