# 클래스 예제와 콜백함수

```javascript
class Counter{
  constructor(runEveryFiveTimes){
    this.counter = 0;
    this.callback = runEveryFiveTimes;
  }
  
  increase(){
    this.counter++;
    console.log(this.counter);
    if(fhis.counter % 5 === 0 ){
        this.callback && this.callback(this.counter);
    }
  }
}
// class에 모든것을 정의하면 컨트롤하기 힘들고, 재사용이 힘들다.
// 콜백함수를 이용해서 만들게되면 쓰는 사람이 자신이 원하는대로 코드를 변경 할 수 있게됨
// -> 클레스의 재사용성이 높아짐

function printSomething(num){
   console.log(`yo!,${num}`);
}

function alertNum(num){
    alert(`Wow!,${num}`);
}

const collCounter = new Counter(); 

const printSomething = new Counter(printSomething); 
const alertNum = new Counter(alertNum); 

coolCounter.increase(); // 1
coolCounter.increase(); // 2
coolCounter.increase(); // 3
coolCounter.increase(); // 4
coolCounter.increase(); // yo!

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://leeboa.gitbook.io/study/_/undefined-3/undefined-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
