Kirk’s PRNG

"Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." --John von Neumann

« Back to blog

Javascript URL Strings

Here's a simple trick I found while looking at some JS library source code today.

If you need to specify a url such as "http://domain.tld/path" in javascript code, some parsing engines may error out with an unterminated string exception after they hit the // and switch into comment mode.

To prevent this, split the string into two parts as shown below.

 var url = "http:/" + "/domain.tld/path"; 

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    twitter