Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 상속
- 페이지네이션
- 스크롤이벤트
- 글또10기x코드트리
- extends
- Filter
- 슬라이딩윈도우
- Spring
- 이진탐색
- xlsx-js-style
- javascript
- supabase authentication
- map
- codepush
- supabase 페이지네이션
- react
- array
- generic
- set
- reactnative
- code-push-standalone
- Next.js
- app.post
- 코드푸시
- meatadata
- interface
- TS
- supabase auth
- 타입스크립트
- async
Archives
- Today
- Total
rhanziy
javascript. class와 callback함수 본문
class Counter {
constructor(runEveryFive){
this.counter = 0;
this.callback = runEveryFive;
}
increase(){
this.counter++;
console.log(this.counter);
if(this.counter % 5 === 0){
this.callback && this.callback(this.counter); // this.callback이 있다면 함수를 실행
}
}
}
function printSomething(num){
console.log(`yo! ${num}`);
}
function alertSomething(num){
alert(`yo! ${num}`);
}
const coolCounter = new Counter(printSomething); // ( ) runEveryFive로 초기화
const sexyCounter = new Counter(alertSomething);
coolCounter.increase();
coolCounter.increase();
coolCounter.increase();
coolCounter.increase();
coolCounter.increase();
sexyCounter.increase();
sexyCounter.increase();
sexyCounter.increase();
sexyCounter.increase();
sexyCounter.increase();
하나의 클래스로 다양한 오브젝트를 만들어 서로 다른 기능을 수행.
=> 클래스의 재사용 가능성이 높아진다.
'Html_css_js' 카테고리의 다른 글
js. JSON을 이용한 localStorage set, get (0) | 2022.02.06 |
---|---|
js. setInterval(), padStart(), append(), Math() (0) | 2022.02.04 |
javascript. Promise API (0) | 2022.01.29 |
javascript. Promise (0) | 2022.01.28 |
javascript. Array배열2(filter, map, reduce, ...) (0) | 2022.01.23 |
Comments