객체지향
-
[JS] chapter14. 객체 지향 - 클로저 모듈 패턴codeStates front-end/Java Script 2023. 1. 13. 10:40
📌클로저 모듈 패턴 메서드 호출 객체.메서드() -> 객체 내에 메서드를 호출하는 방법 ⚠️ 화살표 함수 x 카운터 구현 예제 let counter1 = { value: 0, increase: function() { this.value++ // 메서드 호출을 할 경우, this는 counter1을 가리킵니다 }, decrease: function() { this.value-- }, getValue: function() { return this.value } } counter1.increase() counter1.increase() counter1.increase() counter1.decrease() counter1.getValue() // 2 클로저를 이용해 매번 새로운 객체 생성 클로저란? 함수를 리..