🖊️
Javascript-Advanced
  • Javascript 고급
  • 1) Closure
    • Closure
    • Memory Leak
  • 2) Arrow Function
    • Class To Function ( babel )
    • Normal function vs Arrow Function
    • Class에서 사용하지마!!!
    • 그 외
  • 3) Hidden Class
    • Prototype Chainning
    • Hidden Class
    • Inline Cache
  • 4) setTimeout
    • setTimeout
  • 5) Nodejs
    • Execution-context
    • 내부 동작 원리
    • Crypto
  • 6) Thinking
    • 요청이 무한대로 들어오면 어떻게 될까?
Powered by GitBook
On this page
  1. 2) Arrow Function

Class To Function ( babel )

PreviousMemory LeakNextNormal function vs Arrow Function

Last updated 4 years ago

Was this helpful?

CtrlK

Was this helpful?

test는 A prototype 에 정의 / test2 - class A에 정의

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

"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은 새로 할당하게 된다.