Binding vs Arrow-function (in JavaScript, or for react onClick)

First of all, let’s start with examples of each technique! But the difference is more related to JavaScript language itself. Binding: import React from ‘react’; class MyComponent extends React.Component { constructor(props) { super(props) this.clickHandler = this.clickHandler.bind(this); } clickHandler() { console.log( this ) } render() { return <button onClick={this.clickHandler}>Click Me</button> } } Arrow-function: import React from … Read more

Vue JS: Difference of data() { return {} } vs data:() => ({ })

No difference in your specific example, but there is a very important difference between those two notations, specially when it comes to Vue.js: the this won’t reflect the vue instance in arrow functions. So if you ever have something like: export default { props: [‘stuffProp’], data: () => ({ myData: ‘someData’, myStuff: this.stuffProp }) } … Read more

Can I use ES6’s arrow function syntax with generators? (arrow notation)

Can I use ES6’s arrow function syntax with generators? You can’t. Sorry. According to MDN The function* statement (function keyword followed by an asterisk) defines a generator function. From a spec document (my emphasis): The function syntax is extended to add an optional * token: FunctionDeclaration: “function” “*”? Identifier “(” FormalParameterList? “)” “{” FunctionBody “}”