Last active
November 7, 2016 09:53
-
-
Save tadyjp/5806b04fe811d9b6a2000ae7545e7158 to your computer and use it in GitHub Desktop.
JavaScriptでなぜ Object.create(null) を使うのか? ref: http://qiita.com/tady/items/1215a801e178c98deb35
This file contains 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 a = {} | |
var b = Object.create(Object.prototype) |
This file contains 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 users = {} // { アカウント名: 名前 } | |
function addUser(account, name) { | |
// キーが既に登録されていなければ保存 | |
if (!users[account]) { | |
users[account] = name | |
} | |
} | |
addUser('taro', '山田太郎') | |
addUser('taro', '田中太郎') // 保存されない |
This file contains 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
addUser('constructor', '鈴木次郎') // 保存されない |
This file contains 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 users = Object.create(null) // { アカウント名: 名前 } | |
function addUser(account, name) { | |
// キーが既に登録されていなければ保存 | |
if (!users[account]) { | |
users[account] = name | |
} | |
} | |
addUser('taro', '山田太郎') | |
addUser('constructor', '鈴木次郎') // 保存できる |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment