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?
:: is obviously used here to allow either one or two arguments to be passed to the function.
Two colons (::) are used in C++ as a scope resolution operator. This operator gives you more freedom in naming your variables by letting you distinguish between variables with the same name.
With the new one-time binding syntax, we introduce a double-colon before our value: <h1>{{ ::title }}</h1> Angular processes the DOM as usual and once the value has been resolved it removes the particular property from its internal $$watchers list.
The :: is a unary operator that allows: constants, instance methods and class methods defined within a class or module, to be accessed from anywhere outside the class or module.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With