Consider the following code in react + ES6:
import React, { Component } from 'react';
const myFunction=(x,y)=>{
return x*y
};
class MyTest extends Component {
// state comes here
myProperty=(x,y)=>{
return x*y
};
myMethod(x,y){
return x*y
}
render () {
return (<div>
<h2>Result of myMethod: {this.myMethod(2,3)}</h2>
<h2>Result of myProperty: {this.myProperty(2,3)}</h2>
<h2>Result of myFunction: {myFunction(2,3)}</h2>
</div>
);
}
}
export default MyTest;
Here's what the output looks like:
Result of myMethod: 6
Result of myProperty: 6
Result of myFunction: 6
Is there really a difference? Is one preferable to another?