Last active
January 27, 2016 09:33
-
-
Save kkeeth/3e5f674f520de9f7c3fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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