holdanddeepdive / typescript-study

4 stars 0 forks source link

이펙티브 타입스크립트 6장 #22

Open humonnom opened 1 year ago

humonnom commented 1 year ago

아이템 48

this 바인딩 복습

책에서의 외부 변수에 할당한 후 호출하는 예시

window.name='modified';

class A {
    name = 'a';

    log() {
        console.log(this.name);
    }    
};

const a = new A();

a.log(); // 'a'

var method = a.log;

method(); // undefined => type error

window.method(); // 'modified'

아이템 50


아이템 51


아이템 52