Last active
December 9, 2015 01:22
-
-
Save terrierscript/1c3548d5a3db0eb5db3c to your computer and use it in GitHub Desktop.
EcmaScript6のハマり記法問答集(変数編) ref: http://qiita.com/inuscript/items/03b5affa614c50d72d5a
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 = "hoge" // もう忘れていい | |
let b = "fuga" // 変更できる値。mutable | |
const c = "baz" // 変更できない値。immutable |
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
let hoge = "fuga" | |
let obj = { | |
hoge | |
} | |
console.log(obj) | |
// { hoge: "fuga" } |
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 { hoge } = obj | |
console.log(hoge) | |
// "fuga" |
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
let a = { | |
b : { | |
c : "d" | |
} | |
} | |
let { b : { c } } = a | |
console.log(c) // "d" | |
console.log(b) // undefined |
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
let fooFn = function({ hoge, fuga }){ | |
console.log(hoge, fuga) | |
} | |
fooFn({ | |
hoge: "aaa", | |
fuga: "bbb" | |
}) | |
// aaa, bbb |
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
let foo = "baz" | |
let bee = "boo" | |
retrun <Cmp { ...{ foo, bee } } /> | |
// <Cmp foo={foo} bee={bee} /> と同じ |
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
let foo = "baz" | |
let bee = "boo" | |
retrun <Cmp { ...{ foo, bee } } /> | |
// <Cmp foo={foo} bee={bee} /> と同じ |
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
let a = 1 | |
let b = 2 | |
let c = { a, b } | |
let d = { ...{ a, b } } | |
console.log(c) | |
console.log(d) | |
// どっちもこうなる{ a: 1, b:2 } |
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
let b = "foo" | |
let a = { [b] : "baz" } | |
// a = { foo: "baz" } |
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
let b = "foo" | |
let a = { [b] : "baz" } | |
// a = { foo: "baz" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment