알아두고 가기
객체의 속성(property)은 키-값 쌍을 의미한다.
프로그래밍 패러다임이란 그 시대에 (인정된) 개발 방식이다.
(ex. C언어)
메모리사용: 적음
처리속도: 빠름
재활용성: 낮음
코드 이해: 어려움
디버깅 : 어려움
(ex. C++,Java...)
메모리사용: 많음
처리속도: 느림
재활용성: 높음
코드 이해: 쉬움
디버깅 : 쉬움
ECMAScript 6 방식
클래스 클래스명 { 속성 메소드 }
class ClassName { constructor(parameters){ properties; attributes; } methods(); behaviours(); }
ECMAScript 5 방식
function ClassName (parameters){ properties; attributes; } ClassName.prototype.methods = function() ClassName.prototype.behaviours = function()
은닉화 방식
클로저로 변수를 은닉화
#을 이용해 필드 은닉화
내부 구현은 복잡하지만 실제로 노출되는 부분은 단순하다.
실생활에 예로 들면 부품설계는 절차적으로 진행됐지만 겉모습은 단순하며 버튼으로 간단하게 사용할 수 있는 제품이 있다.
라면끓이기 같은 행동(메소드)도 추상화 시킬 수 있겠다.
class는 철수 라면끓이기(){ 1. 냄비를 꺼낸다. 2. 냄비에 물을 넣는다. 3. 냄비를 가스레인지에 올린다. . . . }
class는 철수 라면끓이기(){ 계란 넣을까? -> 계란라면 떡을 넣을까? -> 떡라면 푹 익힐까? 파를 넣을까? . . . }
부모클래스 (기본클래스)
class Grub {
constructor(age, color, food){
this.age = 0;
this.color = 'pink';
this.food = 'jelly';
}
eat () {
return 'Mmmmmmmmm ' + this.food
}
}
module.exports = Grub;
자식클래스 (파생클래스)
const Grub = require('./Grub');
class Bee extends Grub {
constructor (age, color, food, eat, job){
super(food, eat);
this.age = 5;
this.color = 'yellow';
this.job = 'Keep on growing'
}
}
module.exports = Bee;
instance 이해
syntactic sugar 이해
arguments 이해