❓ this.. 어디서 많이 봤는데..

그냥 object일뿐! 근데 실행 콘텍스트를 곁들인..

⚡ 왜 문제일까?

다음의 사례를 살펴보자!

<script>
    function hello(a) {
        this.a = a;
    }
    var bye = new hello(2);
    console.log(bye.a)
</script>

<script>
    function hello() {
        console.log(this);
    }
</script>
<script>
    "use strict";
    function hello() {
        console.log(this);
    }  
    hello();   
</script>
<body>
		<h1 class="myTitle">JS에서 This가 뭐지?</h1>
    <script>
        const myTitle = document.querySelector(".myTitle");

        function hello() {
            console.log(this);
        }

        myTitle.addEventListener("click", hello)
    </script>
  </body>

this 바인딩이 소실되는 경우가 있다?

함수의 참조 값을 전달하는 과정에서 암시적 소설이 일어난다. 진짜 참조 값만 전달한다고 한다..

<script>
    function hello() {
        console.log(this.a);
    }

    const obj = {
        a : 2,
        hello : hello
    }

    const bye = obj.hello;
		
    var a = 1000;

    bye();
</script> //1000

✅ 강제하면 되지 않을까?

<aside> ⚠️ apply()와 거의 동일하지만, call()은 인수 목록을, 반면에 apply()는 인수 배열 하나를 받는다는 점이 중요한 차이점입니다.

</aside>