Last active
May 6, 2020 12:39
-
-
Save duikb00t/4122206f65437381d05cba6316178bba to your computer and use it in GitHub Desktop.
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
let x = { greeting: 'Hello', infotext: 'lorem ispum sit dolor amet' }; | |
let y = Object.assign({}, x); | |
y.greeting = 'Worked'; | |
console.log(x); | |
console.log(y); | |
/* | |
So... what does this o? | |
Explanation: | |
- First we setup an object called, x with a key greeting and infotext. | |
- We create a new Object and we clone it from the previous one. | |
- We can now change the key value easily from the cloned object. | |
Demo: | |
https://es6console.com/jvmb5r70/ | |
*/ |
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 c = {greeting: "hello" } | |
let d, q | |
d = c | |
q = d | |
c.greeting = "Yow"; | |
console.log(d.greeting); | |
console.log(q.greeting); | |
/* | |
So... why does this work? | |
Explanation: | |
- Assignement doesn't copy, you still only have one object, just two names referring to it | |
Demo: | |
https://es6console.com/jvmasn0w/ | |
*/ |
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 Spread operator ... | |
... = SPREAD operator | |
It's basically the deconstructor for an array | |
const a, b, c = ...['foo', 'bar', 'baz']; | |
puts 'foo' in a, 'bar' in b etc, | |
Example: | |
this.errors.push(...errors) === this.errors.push(errors[0], errors[1], etc.) | |
Extra information: | |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax | |
It's also how you can append array items to another array | |
const a = ['foo']; const b = ['bar', ...a]; | |
console.log(b); // ['bar', 'foo | |
const a = ['foo']; const b = ['bar', ...a]; | |
console.log(b); // ['bar', 'foo'] | |
Works only in babel/webpack, no IE support. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment