01. 객체 지향 프로그래밍이란?
# 객체 지향 프로그래밍
: 객체 간의 상호작용을 중심으로 하는 프로그래밍
: 프로퍼티와 메소드로 이루어진 각 객체들의 상호작용을 중심으로 코드를 작성하는 것
# 객체
- 변수 : 객체의 상태
- 함수 : 객체의 행동
# 절차 지향 프로그래밍
: 변수와 함수를 가지고 작업의 순서에 맞게 코드를 작성하는 것
02. 객체 만들기 1-1 : Object-Literal
# Object Literal
: 중괄호 안에 프로퍼티와 메소드를 나열하는 것
03. 객체 만들기 1-2 : Factory function
# factory function
: 객체를 생성해서 리턴하는 함수
04. 객체 만들기 2 : Constructor function
# Constructor function(생성자 함수)
- new 키워드로 객체 생성
- 보통 함수의 첫 알파벳을 대문자로 작성
# this
: Constructor finction으로 생성할 수 있는 해당 객체
function User(email, birthdate) {
this.email = email;
this.birthdate = birthdate;
this.buy = function(item){
console.log(`${this.email} buys ${item.name}`);
};
}
const item = {
name : '스웨터',
price : 30000,
};
const user1 = new User('chris123@google.com','1992-03-21');
05. 객체 만들기 3 : Class
# class
- new 키워드로 생성
- 보통 프로퍼티의 경우 constructor(생성자) 안에 정의하고, 메소드의 경우 construtor 밖에 정의
class User{
//생성자
constructor(email,birthdate){
this.email = email;
this.birthdate = birthdate;
}
buy(item){
console.log(`${this.email} buys ${item.name}`);
}
}
08. 객체 생성해보기
class MakeCar{
constructor(color,speed){
this.color = color;
this.speed = speed;
}
run(){
console.log(`Runs at ${this.speed}`);
}
}
const car1 = new MakeCar('blue', '100km/h');
car1.run();
'FRONTEND > JavaScript' 카테고리의 다른 글
[ 생활코딩 - WEB2 JavaScript ] 강의 내용 정리 (0) | 2022.12.08 |
---|---|
[코드잇 - 자바스크립트 객체 지향 기본기] 2. 객체지향 프로그래밍의 4개의 기둥 : 추상화, 캡슐화, 상속, 다형성 (0) | 2022.11.22 |
[코드잇 - 모던 자바스크립트] 06. 자바스크립트 모듈 (0) | 2022.11.22 |
[코드잇 - 모던 자바스크립트] 05. 자바스크립트의 유용한 내부 기능 (0) | 2022.11.21 |
[코드잇 - 모던 자바스크립트] 04. 자바스크립트의 문법과 표현 (0) | 2022.11.17 |