July 2009
2 posts
1 tag
When semicolons are NOT optional in JavaScript
An inadvertently skipped semicolon recently left me scratching my head over a runtime error. The code looked something like this: // Add a new function to an existing namespace some.namespace.doSomething = function () { // ... } // Define more functions inside a closure to hide some helpers (function () { // ... })(); This was giving me a “yada yada yada… is not a...
Jul 23rd
1 tag
Parsing query string parameters into a collection
Here’s a utility function for parsing query parameters: function getQueryParams(qs) { qs = qs.split("+").join(" "); var params = {}; var tokens, re = /[?&]?([^=]+)=([^&]*)/g; while (tokens = re.exec(qs)) { params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); } return params; } //var query =...
Jul 8th