[Javascript] prototype

Ben Curtis Quixote at LaMancha.org
Mon Jul 23 23:42:23 CDT 2001


> What can people tell me about the prototype method of some client side
> objects. I have a function I would like to add as a method of the location
> object that can return an item in the querystring like the asp object. Can
> someone direct me how this is done?

I don't think you need the prototype for this one. For example, this works
in the few browsers I've tested:

var NmVl = location.search.substring(1).split('&');
var Qry = new Array();
for (var xx=0; xx<NmVl.length; xx++) {
  var Pair = NmVl[xx].split('=');
  Qry[unescape(Pair[0])] = unescape(Pair[1]);
}
location.query = Qry;


Then you can reference like so:

foo.com/bar.cgi?user=Bob&type=human

location.query["user"] is "Bob"
location.query["type"] is "human"


Your function may be more powerful or intuitive than this simple array, but
I think you would just need to attach it like so:

location.query = myfunction;

so that:

location.query('user') is "Bob"...

--
+Ben Curtis
...leveraging synergy right out of the box.









More information about the Javascript mailing list