Skip to content

Instantly share code, notes, and snippets.

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