ES7 property initializers

# Benjamin (Inglor) Gruenbaum (8 years ago)

Looking at the syntax from here:

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() {
            count: this.state.count + 1 

    render() {
        return ( <div onClick={this.tick.bind(this)}> Clicks: { this.state.count } </div> ); 

Also discussed here:


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?

# Jeff Morrison (8 years ago)

I am working on a proposal that I intend to bring to the next TC39 meeting. The (very much in need of updating) gist for my proposal is here:

(Note that this gist is from July of last year, which was before we eliminated @@create and imposed the new super() allocation semantics for derived classes -- so it needs to be updated to reflect those two changes. Hopefully I can find some time to update it in the next week or two)