바르고 뜨겁게
Vanilla JS - classes (자바스크립트 객체 지향 프로그래밍) 본문
Vanilla JS - classes (자바스크립트 객체 지향 프로그래밍)
프로그래밍 패러다임
함수형 프로그래밍(Functional Programming)
객체 지향 프로그래밍(OOP-ObjectOrientedProgramming)
ES6 부터 자바스크립트에서 객체 지향 프로그래밍이 가능하다.
class Human{
constructor(name, lastName){
this.name = name;
this.lastName = lastName;
}
}
// Human 상속
const myName = new Human("Right","Hot");
console.log(myName);
console.log(myName.name);
console.log(myName.lastName);
class Baby extends Human{
cry(){
console.log("Waaaaaaaaa");
}
sayName(){
console.log(`My name is ${this.name} ${this.lastName}`)
}
}
const myBaby = new Baby("RightHot","Jr");
console.log(myBaby);
myBaby.cry();
myBaby.sayName();
Human {name: "Right", lastName: "Hot"}
Right
Hot
Baby {name: "RightHot", lastName: "Jr"}
Waaaaaaaaa
My name is RightHot Jr
'자바스크립트 > Vanilla Js' 카테고리의 다른 글
Vanilla JS - Array.filter (0) | 2019.05.22 |
---|---|
Vanilla JS - Array.map (0) | 2019.05.21 |
[자바스크립트] 오브젝트에서 변수 꺼내기 (비구조화 할당 Object Destructuring) (0) | 2019.05.17 |
Vanilla JS - async/await (0) | 2018.12.13 |
Vanilla JS - 콜백(callback)과 프로미스(promise) 비교 (0) | 2018.12.12 |
Comments