Last active
November 6, 2018 16:42
-
-
Save sekky0905/d09fb5a864d8562cd3022635df30d306 to your computer and use it in GitHub Desktop.
オブジェクト初期化子で計算されたプロパティやキーを使用する ref: https://qiita.com/Sekky0905/items/95b771ba209c73ded201
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
const ADDRESS = 'ADDRESS'; | |
const user = { | |
id : 1, | |
[ADDRESS] : 'hoge', | |
['MAIL_' + ADDRESS] : 'foo' | |
} | |
alert(`user : ${JSON.stringify(user)}`); |
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
const user = { | |
id : 1, | |
ADDRESS : 'hoge', | |
MAIL_ADDRESS : 'foo' | |
} | |
alert(`user : ${JSON.stringify(user)}`); |
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
user : {"id":1,"ADDRESS":"hoge","MAIL_ADDRESS":"foo"} |
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
const SHOW = 'SHOW'; | |
const hoge = { | |
// メソッド名としてSHOWを使用している | |
[SHOW](target) { | |
alert(target); | |
} | |
} | |
// hoge objectのSHOWメソッドを呼び出す。 | |
hoge[SHOW]('JavaScript'); |
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
const SHOW = 'SHOW'; | |
const hoge = { | |
// メソッド名としてSHOWを使用している | |
SHOW(target) { | |
alert(target); | |
} | |
} | |
// hoge objectのSHOWメソッドを呼び出す。 | |
hoge.SHOW('JavaScript'); |
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
JavaScript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment