React

by davebeaumont

HTML

<div id="container">
  <!-- This element's contents will be replaced with your component. -->
</div>

React

class FootballPlayerComponent extends React.Component {
 
 constructor() {
        super();
        this.purchasePlayer = this.purchasePlayer.bind(this);
    }
 
 render() {
        return (
            <div className="football-player-controls">
                <button name="purchase" onClick={this.purchasePlayer}>
                    Purchase
                </button>
            </div>
        );
    }
 purchasePlayer() {
        //This is now populated thanks to the ES5 bind syntax in the constructor.
        console.log(this); 
    }
}

ReactDOM.render(
  <FootballPlayerComponent />,
  document.getElementById('container')
);