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
| // All of the following Non-iterable data types will throw errors | |
| Object.fromEntries(undefined); // undefined | |
| Object.fromEntries(null); // null | |
| Object.fromEntries(true); // boolean | |
| Object.fromEntries(100); // number | |
| Object.fromEntries("hi"); // string | |
| Object.fromEntries({key: "value"}); // object | |
| Object.fromEntries([1,2,3); // single value array |
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
| const a = { | |
| foods: { | |
| dinner: 'Pasta' | |
| } | |
| }; | |
| let b = JSON.parse(JSON.stringify(a)) | |
| b.foods.dinner = 'Soup' |
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
| const a = { | |
| foods: { | |
| dinner: 'Pasta' | |
| } | |
| }; | |
| let b = {...a, foods: {...a.foods}} | |
| b.foods.dinner = 'Soup' |
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
| const a = { | |
| foods: { | |
| dinner: 'Pasta' | |
| } | |
| }; | |
| let b = {...a} | |
| b.foods.dinner = 'Soup' // PROBLEM: changes for both objects |
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
| const a = { | |
| en: 'Bye', | |
| de: 'Tschüss' | |
| }; | |
| let b = Object.assign({}, a) | |
| b.de = 'Ciao'; | |
| console.log(b.de) // Ciao |
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
| const a = { | |
| en: 'Bye', | |
| de: 'Tschüss' | |
| }; | |
| let b = {...a}; // Spread Operator | |
| b.de = 'Ciao'; | |
| console.log(b.de); // Ciao |
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
| const a = { | |
| en: 'Hello', | |
| de: 'Hallo', | |
| es: 'Hola', | |
| pt: 'Olà' | |
| }; | |
| let b = a; | |
| b.pt = 'Oi'; |
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
| const wordCountElement = document.createElement('p'); | |
| wordCountElement.className = 'wordCount'; | |
| wordCountElement.innerHTML = 'Word Count: <strong id="blogWordCount">0</strong>'; | |
| document.body.appendChild(wordCountElement); | |
| const blogObserver = new EventObserver(); | |
| blogObserver.subscribe((text) => { | |
| const blogCount = document.getElementById('blogWordCount'); |
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
| function MacBook() { | |
| this.cost = function () { return 997; } | |
| this.screenSize = function () { return 11.6; }; | |
| } | |
| // Decorator 1 | |
| function Memory ( macbook ) { | |
| var v = macbook.cost(); | |
| macbook.cost = function() { | |
| return v + 75; |
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
| var carFactory = new VehicleFactory(); | |
| var car = carFactory.createVehicle({ | |
| vehicleType: "car", | |
| color: "yellow", | |
| doors: 6, | |
| }); | |
| console.log(car instanceof Car); // true | |
| console.log(car); // Car object of color "yellow", doors: 6 in a "brand new" state |