Skip to content

Instantly share code, notes, and snippets.

View gpDA's full-sized avatar
🏠
Working from home

GP LEE gpDA

🏠
Working from home
View GitHub Profile
// 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
const a = {
foods: {
dinner: 'Pasta'
}
};
let b = JSON.parse(JSON.stringify(a))
b.foods.dinner = 'Soup'
const a = {
foods: {
dinner: 'Pasta'
}
};
let b = {...a, foods: {...a.foods}}
b.foods.dinner = 'Soup'
const a = {
foods: {
dinner: 'Pasta'
}
};
let b = {...a}
b.foods.dinner = 'Soup' // PROBLEM: changes for both objects
const a = {
en: 'Bye',
de: 'Tschüss'
};
let b = Object.assign({}, a)
b.de = 'Ciao';
console.log(b.de) // Ciao
const a = {
en: 'Bye',
de: 'Tschüss'
};
let b = {...a}; // Spread Operator
b.de = 'Ciao';
console.log(b.de); // Ciao
const a = {
en: 'Hello',
de: 'Hallo',
es: 'Hola',
pt: 'Olà'
};
let b = a;
b.pt = 'Oi';
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');
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;
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