0

Cannot figure out why bind is not working with IIFE inside object method? What I've missed?

Thanks in advance.

Example:

var a = {
  b: () => console.log('Hello'),
  c: (() => this.b()).bind(a)()
}

a.b()
a.c
// Error: Uncaught TypeError: this.b is not a function
Max Travis
  • 1,228
  • 4
  • 18
  • 41
  • There is no answer inside the recommended post. Please, I really need an explanation why... – Max Travis Jun 17 '19 at 10:57
  • Thanks. I read, btw there is no explanation correspond to my problem. FYI – Max Travis Jun 17 '19 at 11:05
  • 1
    You're trying to reference the `b` property in the object initializer, which doesn't work because the object hasn't been initialized yet. You're also referencing `this.b` in an attempt to get to the `b` property, but arrow functions inherit the `this` from their outer scope – CertainPerformance Jun 17 '19 at 11:16
  • @CertainPerformance I've tried such a way because of the `c: (() => this.b())()` does not work (where we expect that arrow func will grab local `this` context by itself, but it's not happen). – Max Travis Jun 17 '19 at 11:22

0 Answers0