[Javascript] Function Constructor question

Parkes, Rohan parkesr1 at anz.com
Thu Jul 19 23:51:40 CDT 2001


I was working on a function that would allow me to request querystrings
client-side using the same syntax as ASP:

request.querystring("whatever");

In order to do this, I made use of the new Function constructor, so that the
parameter to querystring would be passed to an anonymous function stored in
the querystring property of the function:

this.querystring = new Function("key", "return value;");

Of course, it turned out that I wasn't the first to have this idea. I found
a similar, but more sophisticated version on the Different ASPect site.
However, the author uses 

this.querystring = function (qsVar) { return value };	

I've never seen this kind of syntax - I've always understood that you need
to use the "new" keyword, and write the function code as a string. Can
anyone clarify this for me? Obviously, it works, but is it browser-specific,
or only available in a recent JS version?

Rohan Parkes



More information about the Javascript mailing list