Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does :: (double colon) mean in JavaScript? [duplicate]

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?

like image 820
Alexander M. Avatar asked Aug 16 '16 14:08

Alexander M.


People also ask

What is :: in JS?

:: is obviously used here to allow either one or two arguments to be passed to the function.

What does double colon mean in code?

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.

What does double colon mean in Angularjs?

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.

What is :: double colon in Ruby on Rails?

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.


1 Answers

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.

like image 55
ssube Avatar answered Oct 05 '22 08:10

ssube