Skip to main content
larsw86433957
Participant
March 24, 2020
Question

HTML5 .bind(this) what?

  • March 24, 2020
  • 1 reply
  • 591 views

I am trying to wrap my head around the HTML5 alternate code. I am trying to wrap my head around the .bind(this);

this.button_1.addEventListener("click", fl_ClickToGoToAndPlayFromFrame.bind(this));

I understand 'this' for the start and it is reffereing to this instance ( I think). But then the call to teh function adds .bind(this). What is the purpose of this when simply calling a function? I tried to revove it, but that casued it to no longer work.

 

Also, is the 'fl_' important to have in the function name?

 

Thanks. 

    This topic has been closed for replies.

    1 reply

    Legend
    March 24, 2020

    Bind forces a function to execute in the desired context, which means the value of "this". Without it, all event handlers execute in the global context, which means "this" points to the browser window object. This is only a problem if the event handler uses "this". Apparently yours does.

    larsw86433957
    Participant
    March 24, 2020

    Thank you for explaning it.