1
let obj = {
    a: "obj foo a"
}

this.a = 1

let foo = () => {
    // this.a = 34;
    setTimeout(() => {
        console.log(this); /// this is not bound at all
    }, 100)
}

foo();
var baz = foo.bind(obj);

baz();
obj.a = "The new A value";

How to bind an obj to the foo function to access it inside timeout.

Mr AJ
  • 1,515
  • 3
  • 24
  • 40
  • 6
    You can't bind `this` in an arrow function, having a lexically defined `this` value is the entire point of arrow functions – Jared Smith Aug 27 '20 at 13:46
  • Answer is here: https://stackoverflow.com/questions/33308121/can-you-bind-this-in-an-arrow-function – Anton Aug 27 '20 at 13:48
  • 1
    Heh, you know, everyone has cars with drivers. But me, I got a self automated car. It's great! But you know what would make it better? If it had a driver.... – Taplar Aug 27 '20 at 13:50

0 Answers0