Skip to content

Instantly share code, notes, and snippets.

@haribote
Last active August 29, 2015 14:00
Show Gist options
  • Save haribote/11136198 to your computer and use it in GitHub Desktop.
Save haribote/11136198 to your computer and use it in GitHub Desktop.
/*
* _.parseUrlQuery.js
* - Urlクエリーを解析してlocationオブジェクトを拡張する
* - Underscore.js が必要
*/
;(function(window, undefined) {
location.query = {};
var queryString = location.search.substring(1);
if (queryString.length > 0) {
_.extend(location.query, _.chain(queryString.split('&'))
.map(function(prop) {
var keyVal = prop.split('=');
return [keyVal[0], decodeURIComponent(keyVal[1])];
})
.object()
.value()
);
}
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment