> For the complete documentation index, see [llms.txt](https://organization-bht.gitbook.io/it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organization-bht.gitbook.io/it/undefined-1/react-with-typescript/es6+/2.-arrowfunction.md). Agents can also search and read this documentation through its [MCP server](https://organization-bht.gitbook.io/it/~gitbook/mcp).

# 연습문제 2. ArrowFunction

## 1) 눈코딩

```javascript
const obj = {
    name: "홍길동",
    normalFn: function() {
        console.log("일반 함수:", this.name);
    },
    arrowFn: () => {
        console.log("화살표 함수:", this.name);
    }
};

obj.normalFn(); // ??
obj.arrowFn();  // ??
```

## 2) 눈코딩

```javascript
const person = {
    name: "안찰스",
    greet: function() {
        const innerArrow = () => console.log(this.name);
        const innerNormal = function() { console.log(this.name); };
        
        innerArrow();
        innerNormal();
    }
};

person.greet();
// innerArrow 출력: 
// innerNormal 출력: 
```

## 3) 눈코딩

* 1초 간격으로 Hello , 찰스를 출력하려고 하나 이름값이 제대로 출력되지 않았다.
* 문제의 원인과 수정방안을 생각하세요

```javascript
function User(name) {
    this.name = name;
    setTimeout(function() {
        console.log("Hello, " + this.name);
    }, 1000);
}

new User("찰스"); // "Hello, undefined"
```

## 4) 눈코딩

```javascript
const tom = {
    name : 'Tom',
    sayName : function(){
        console.log(this.name);
    }
}

const alice = { name: "Alice" };

tom.sayName(); // ??
tom.sayName.call(alice); // ??
```

## 5) 눈코딩

```javascript
this.tag = "Error";

function print() {
  console.log(this.tag); 
}
const obj = { tag: "OK" };

const boundPrint = print.bind(obj);

print(); // ??
boundPrint(); // ??
```
