What does :: (double colon) mean in JavaScript?

JavascriptReactjs

Javascript Problem Overview


I have got some JSX code in a react app like this:

...
 _renderSignOutLink() {
    if (!this.props.currentUser) {
      return false;
    }

    return (
      <a href="#" onClick={::this._handleSignOutClick}><i className="fa fa-sign-out"/> Sign out</a>
    );
...

What does the double colon, ::, mean before calling the function?

Javascript Solutions


Solution 1 - Javascript

The :: is a proposed binding operator that desugars into a bound function:

::foo.bar
// becomes
foo.bar.bind(foo)

This is useful in React (and any other event handlers) because it means this will have the expected value (instance of the class) when the event handler is later invoked.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexander M.View Question on Stackoverflow
Solution 1 - JavascriptssubeView Answer on Stackoverflow