Benjamin (Inglor) Gruenbaum (2015-02-10T12:47:52.000Z)
monolithed at gmail.com (2015-02-10T13:32:26.371Z)
Looking at the syntax from here: http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers ES7+ Property Initializers Wait, assigning to properties seems like a very imperative way of defining classes! You're right, however, we designed it this way because it's idiomatic. We fully expect a more declarative syntax for property initialization to arrive in future version of JavaScript. It might look something like this: ```js // Future Version export class Counter extends React.Component { static propTypes = { initialCount: React.PropTypes.number }; static defaultProps = { initialCount: 0 }; state = { count: this.props.initialCount }; tick() { this.setState({ count: this.state.count + 1 }); } render() { return ( <div onClick={this.tick.bind(this)}> Clicks: { this.state.count } </div> ); } } ``` Also discussed here: https://github.com/6to5/6to5/issues/619 Are there any plans to specify this? Are there any proposals being worked on to specify syntax similar to this or alternative syntax addressing this?
monolithed at gmail.com (2015-02-10T13:32:11.861Z)
Looking at the syntax from here: http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers ES7+ Property Initializers Wait, assigning to properties seems like a very imperative way of defining classes! You're right, however, we designed it this way because it's idiomatic. We fully expect a more declarative syntax for property initialization to arrive in future version of JavaScript. It might look something like this: // Future Version ```js export class Counter extends React.Component { static propTypes = { initialCount: React.PropTypes.number }; static defaultProps = { initialCount: 0 }; state = { count: this.props.initialCount }; tick() { this.setState({ count: this.state.count + 1 }); } render() { return ( <div onClick={this.tick.bind(this)}> Clicks: { this.state.count } </div> ); } } ``` Also discussed here: https://github.com/6to5/6to5/issues/619 Are there any plans to specify this? Are there any proposals being worked on to specify syntax similar to this or alternative syntax addressing this?
monolithed at gmail.com (2015-02-10T13:31:56.362Z)
Looking at the syntax from here: http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#es7-property-initializers ES7+ Property Initializers Wait, assigning to properties seems like a very imperative way of defining classes! You're right, however, we designed it this way because it's idiomatic. We fully expect a more declarative syntax for property initialization to arrive in future version of JavaScript. It might look something like this: // Future Version export class Counter extends React.Component { static propTypes = { initialCount: React.PropTypes.number }; static defaultProps = { initialCount: 0 }; state = { count: this.props.initialCount }; tick() { this.setState({ count: this.state.count + 1 }); } render() { return ( <div onClick={this.tick.bind(this)}> Clicks: { this.state.count } </div> ); } } Also discussed here: https://github.com/6to5/6to5/issues/619 Are there any plans to specify this? Are there any proposals being worked on to specify syntax similar to this or alternative syntax addressing this?