What does :: (double colon) mean in JavaScript?
JavascriptReactjsJavascript 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.