4 ms·
C'mon. > Right away, you'll notice a subtle difference – a more terse syntax is available to you when defining classes: // The ES5 way var Photo = Rea
by tel 11y ago
C'mon.
> Right away, you'll notice a subtle difference – a more terse syntax is available to you when defining classes:
// The ES5 way
var Photo = React.createClass({
handleDoubleTap(e) { … },
render() { … },
});
// The ES6+ way
class Photo extends React.Component {
handleDoubleTap(e) { … }
render() { … }
}
It may or may not be more terse in longer examples, but ES6 already supports things to make the class syntax less terse here by about the same margin the article claims.
- adregan 11y agoWhile it doesn't add up to a terribly large amount of extra characters, you are missing the function keyword (ie. `handleDoubleTap: function(e)`) in the ES5 example.
- tel 11y agoAh, now I think I understand what they were trying to argue—full ES5 versus ES6 where I took it to be ES6 versus ES6-using-class.