Skip to content
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

Autobinding instead of binding in the constructor #158

Closed
nikgraf opened this issue Feb 11, 2016 · 6 comments
Closed

Autobinding instead of binding in the constructor #158

nikgraf opened this issue Feb 11, 2016 · 6 comments

Comments

@nikgraf
Copy link
Contributor

nikgraf commented Feb 11, 2016

See https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding

Prebinding in the constructor:

class Counter extends React.Component {
  constructor() {
    super();
    this.tick = this.tick.bind(this);
  }
  tick() {
    ...
  }
  ...
}

Syntactical sugar:

class Counter extends React.Component {
  tick = () => {
    ...
  }
  ...
}
@mxstbr
Copy link
Member

mxstbr commented Feb 11, 2016

Oooh I didn't know about that, much nicer! Would love a PR for this.

@mxstbr mxstbr added this to the v3.0 milestone Feb 11, 2016
@mxstbr mxstbr changed the title What about using the syntactical instead of prebinding in the constructor. ES6 autobinding instead of binding in the constructor Feb 12, 2016
@jbinto
Copy link
Contributor

jbinto commented Feb 13, 2016

FWIW, that syntax (class fields/static properties) isn't an ES6 feature, it is a stage 1 proposal that has support only in Babel.

I don't have a problem with using experimental syntax but I definitely think it's worth documenting anything like this, since it could change on a whim. Docs should make it clear the project relies on experimental language features, which ones, and why.

@mxstbr mxstbr changed the title ES6 autobinding instead of binding in the constructor Autobinding instead of binding in the constructor Feb 13, 2016
@mxstbr
Copy link
Member

mxstbr commented Feb 13, 2016

👍 Thanks for the notice, I hope I don't forget to document it!

@jbinto
Copy link
Contributor

jbinto commented Feb 13, 2016

I opened #165 to track it.

@mxstbr
Copy link
Member

mxstbr commented Feb 13, 2016

Thanks @jbinto, closing this issue!

@lock
Copy link

lock bot commented May 30, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants