Learn JavaScript NESTED OBJECTS easy! 📫

Опубликовано: 21 Ноябрь 2023
на канале: Bro Code
24,653
622

00:00:00 example 1
00:04:24 example 2

// nested objects = Objects inside of other Objects.
// Allows you to represent more complex data structures
// Child Object is enclosed by a Parent Object

// Person{Address{}, ContactInfo{}}
// ShoppingCart{Keyboard{}, Mouse{}, Monitor{}}

class Person{

constructor(name, age, ...address){
this.name = name;
this.age = age;
this.address = new Address(...address);
}
}

class Address{

constructor(street, city, country){
this.street = street;
this.city = city;
this.country = country;
}
}

const person1 = new Person("Spongebob", 30, "124 Conch St.",
"Bikini Bottom",
"Int. Waters");

const person2 = new Person("Patrick", 37, "128 Conch St.",
"Bikini Bottom",
"Int. Waters");

const person3 = new Person("Squidward", 45, "126 Conch St.",
"Bikini Bottom",
"Int. Waters");


console.log(person1.name);
console.log(person1.age);
console.log(person1.address);
console.log(person1.address.street);
console.log(person1.address.city);
console.log(person1.address.country);


На этой странице сайта вы можете посмотреть видео онлайн Learn JavaScript NESTED OBJECTS easy! 📫 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Bro Code 21 Ноябрь 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 24,653 раз и оно понравилось 622 зрителям. Приятного просмотра!