Highlighted

HTML5 .bind(this) what?

New Here ,
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

97

Likes

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

HTML5 .bind(this) what?

New Here ,
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

98

Likes

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
Mar 24, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Mar 24, 2020 0
New Here ,
Mar 24, 2020

Copy link to clipboard

Copied

Thank you for explaning it.

Likes

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
Reply
Loading...
Mar 24, 2020 0