let person = {
  name: 'wow',
  wow: function () {
    console.log(this); //name 이 wow로 출력됨.
    setTimeout(function () {
      console.log(this); //여기서는 this가 windwo로 설정되어있기에 bind를 활용해야함.
    }, 1000);
  },
};
person.wow();
let person = {
  name: 'wow',
  wow: function () {
    setTimeout(
      (function () {
        console.log(this); //여기서는 this가 windwo로 설정되어있기에 bind를 활용해야함.
      }).bind(this),
    1000);
  },
};
person.wow();
let person = {
  name: 'wow',
  wow: function () {
    function hey() {
      console.log(this);
    }
    setTimeout(hey.bind(this), 1000);
  },
};
person.wow();

'🖥️FE🖥️' 카테고리의 다른 글

JS sharing data  (0) 2023.04.08
Script defer  (0) 2023.04.04
window  (0) 2023.03.30
HTML  (0) 2023.03.03
Jumpit & Jocoding  (0) 2022.12.09

+ Recent posts