Last active
March 1, 2017 06:26
-
-
Save markerikson/27b44b7b0618adaedbf1d9900aa9ea58 to your computer and use it in GitHub Desktop.
Javascript `...` syntax meanings
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
| // See https://rainsoft.io/how-three-dots-changed-javascript/ for more detail on some of these | |
| // ES6 arrays | |
| // Array spread operator | |
| const newArray = [...oldArray, newItem]; | |
| // Array destructuring | |
| const [first, second, ...everythingElse] = someArray; | |
| // ES6 functions | |
| // Function rest arguments | |
| function functionWithManyArgs(firstArg, secondArg, ...allOtherArgs) {} | |
| // Function application | |
| const otherArgs = ["c", "d", "e"]; | |
| someFunction("a", "b", ...otherArgs); | |
| // Object Spread syntax (currently a Stage 3 proposal) | |
| // Object spread operator | |
| const newObject = {...oldObject, {someKey : someValue}}; | |
| // Rest spread operator | |
| const {a, b, ...allOtherFields} = someObject; | |
| // JSX object prop spread syntax (not an actual standard) | |
| const someObject = {a : 42, b : "some string", c : [1, 2, 3] }; | |
| return <SomeComponent {...someObject} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment