• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

HTML5 .bind(this) what?

New Here ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

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. 

Views

466

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

LATEST

Thank you for explaning it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines