When creating a React class, which is preferable?
export default class Foo extends React.Component {
constructor (props) {
super(props)
this.doSomething = this.doSomething.bind(this)
}
doSomething () { ... }
}
or
export default class Foo extends React.Component {
doSomething = () => { ... }
}
A coworker of mine thinks that the latter causes memory problems because babel transpiles the code to capture this
inside the closure, and that reference will cause the instance to not be cleaned by GC.
any thoughts about this?