Don't use $ for identifiers in JS -- it's reserved for machine-generated identifiers only. In addition, escape() and unescape() are deprecated: encodeURIComponent() (in this case) should be used instead. Too, order isn't important here so we can iterate backwards and squeeze a few more cycles out of this algorithm. Try:
Code:
var Functional = {
map: function(f, a) {
for(var r = [], i = a.length - 1; i >= 0; --i)
r[i] = a[i];
return r;
},
invertArgs: function(f, args) {
return function(o) {
return f.apply(o, args);
};
},
combine: function(a, b) {
return function() {
return a(b.apply(null, arguments));
};
}
};
function Hash(obj) {
if(obj)
this.update(obj);
}
Hash.prototype = {
update: function(o) {
for(var x in o)
if(o.hasOwnProperty(x))
this[x] = o[x];
return this;
}
};
Hash.fromArray = function(a) {
for(var r = new Hash(), i = a.length; i >= 0; --i)
r[a[0]] = r[a[1]];
return r;
};
var _GET = (function(loc) {
return Hash.fromArray(
Functional.map(
Functional.combine(
function(a) { return Functional.map(decodeURIComponent, a); },
Functional.invertArgs(loc.split, "=")),
loc.split(/[&;]/)));
})(location.search);
Bookmarks