Created
June 30, 2015 23:49
-
-
Save chuck0523/5a9e83b8bdeea8738f64 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
| //Enhanced object literals | |
| //変数名と同じキーや無名関数のfunctionを省略できる | |
| var name = 'chuck', age = '24'; | |
| //ES5 | |
| var person = { | |
| name : name, | |
| age : age, | |
| hi : function() {return 'hi';} | |
| }; | |
| //ES6 | |
| var person = { | |
| name, age, hi() {return 'hi';} | |
| }; | |
| //keyに動的な値を使用できる。 | |
| var rand = Math.random(); | |
| //ES5 | |
| var obj = {}; | |
| obj[rand] = 'value'; | |
| //ES6 | |
| var obj = {[rand]: 'value'}; | |
| console.log(obj); | |
| // Object {0.2180616082623601: "value"} | |
| var obj2 = {[Math.ramdom()]: 'value'}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment