> For the complete documentation index, see [llms.txt](https://bugtype-kr.gitbook.io/javascript-advanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bugtype-kr.gitbook.io/javascript-advanced/arrow-function/class-to-function-babel.md).

# Class To Function ( babel )

![test는 A prototype 에 정의 / test2 - class A에 정의](https://135440697-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MNxPpymVr-cx-VEG-Kr%2F-MPcr93Jq4-HkIuajfJe%2F-MPcrPCGgF50fU5Ci-tx%2Fimage.png?alt=media\&token=2cc065e8-cae1-46a9-b4b5-9abe3c566165)

```typescript
class A{
    test(){}
    test2 = () => {}
}
```

```typescript
"use strict";
var A = /** @class */ (function () {
    function A() {
        this.test2 = function () { };
    }
    A.prototype.test = function () { };
    return A;
}());
```

class를 function으로 변환하면, method는 prototype에 선언된다.

하지만 arrow function은 보는 거와 같이 A 인스턴스에 선언 된다.

A 인스턴스를 100개 만든다면, prototype(hidden class, shape)가 공유되므로, 메모리를 새로 할당하지 않는다. 하지만 arrow function은 새로 할당하게 된다.
