Skip to content

Why symbol :: is needed in onClick={::this.handleToggleKitten} ? #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
whatifif opened this issue Jan 10, 2016 · 2 comments
Closed

Why symbol :: is needed in onClick={::this.handleToggleKitten} ? #799

whatifif opened this issue Jan 10, 2016 · 2 comments

Comments

@whatifif
Copy link

I know that symbol :: is used to call a static method in PHP language.

I see this symbol is used in source code of this react-redux-universal-hot-example like below in "About Us" page:
onClick={::this.handleToggleKitten}

Why this should not be onClick={this.handleToggleKitten} without symbol :: ?

Thanks in advance

@isilweo
Copy link
Contributor

isilweo commented Jan 10, 2016

this is function bind operator, it does not work like :: in PHP. You can read about it on link below
http://babeljs.io/blog/2015/05/14/function-bind/ or https://github.com/zenparsing/es-function-bind
It is proposed for ES7 and is currently on stage 0.

{::this.handleToggleKitten} is equivalent of this.handleToggleKitten.bind(this)

It was also removed from source code on this repo with PR #547

@whatifif
Copy link
Author

Thanks for your kind explanation.

I think that using the arrow function is a better way than using this new symbol :: for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants