/
Don't use => syntax for anonymous functions

Don't use => syntax for anonymous functions

One can write an anonymous function like this in Javascript:

$Button.on('click', (event) => { alert("button clicked'); });

It’s better not to. It just doubles the amount of syntax one can use to solve this problem which increases cognitive load for the team maintaining the code.

It’s better to use this format:

$Button.on('click', function(event) { alert("button clicked'); });

The second format is more widely understood. Best to use a subset of the features of Javascript.

Same reasoning as why it’s better not to write static C methods and instead use C functions in C++.

Related content

Progress function for animation effects from first principles
Progress function for animation effects from first principles
Read with this
Dealing with loops with create Closures
Dealing with loops with create Closures
More like this
Best practices for handle click events for GUIs with many child elements resulting from application data
Best practices for handle click events for GUIs with many child elements resulting from application data
Read with this
The equality operator in Javascript == does implicit type conversions
The equality operator in Javascript == does implicit type conversions
More like this
Do not store application data in the DOM
Do not store application data in the DOM
Read with this
Javascript Namespace Conventions
Javascript Namespace Conventions
More like this