Skip to content

Instantly share code, notes, and snippets.

@kkeeth
Last active January 27, 2016 09:33
Show Gist options
  • Save kkeeth/3e5f674f520de9f7c3fe to your computer and use it in GitHub Desktop.
Save kkeeth/3e5f674f520de9f7c3fe to your computer and use it in GitHub Desktop.
var obj = {
id: 16,
val: 'hogehoge',
}
function make_query(obj){
var keys = Object.keys(obj);
if(!keys.length) return "";
return "?" + keys.map(function(key){
return encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]);
}).join("&");
}
console.log(make_query(obj));
// http://blog.asial.co.jp/1101 より引用
// モジュールの作り方
var Person = (function(){
var _name = 'hogehoge',
_age = 99;
function _init() {
// 何らかの処理
}
function _getName() {
return _name;
}
function _getAge() {
return _age;
}
function _updateName(updateName) {
_name = updateName;
}
// 初期化を実行する
_init();
// 公開APIを返す
return {
getName : _getName,
getAge : _getAge,
updateName: _updateName
};
}());
// 使い方
Person.getName();
Person.getAge();
Person.updateName('fugafuga');
Person.getName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment