I love the book Getting Started with p5.js that is published by Maker Media. The examples included are very helpful, but since the book is from 2016, those examples do not utilize function expressions or arrow syntax for defining functions.
Should we give preference to those techniques for writing function definitions in p5.js code, or does it not really matter? If using those techniques is preferred, are there any other introductory p5.js books that demonstrate the most recent developments in JavaScript?
Admittedly, the above might not be an important issue, since it is pretty simple to edit function definitions later on to adapt them to whatever syntax is preferred at the time. However, I would like to develop good habits by favoring whatever coding styles are generally deemed best.
Functions defined using fat arrow => syntax (aka lambdas) have a fixed value for the keyword this when used inside their body; which is determined at the moment the arrow function is created, capturing the current value of this in its surrounding!
That’s why arrow functions should not be used for defining methods or when we require a dynamic value for keyword this based on the object invoking them.
Of course, if we don’t care or use keyword this inside a function’s body, the syntax we use for creating a function is a personal preference.
A noble pursuit for sure! However, the p5js library is 1 of the many flavors of Processing, which are available for other programming languages too, using different syntaxes.
A Processing flavor doesn’t care much about using the best practices of a given language; rather they prefer using hacks and other techniques which would make them easier for artists and other creative folks.
Thanks for that and the other detailed information you have provided. That advice is much appreciated! It does offer the perspective that the best techniques to emulate would be practices of the Processing community that make creative coding comfortable and enjoyable for artists, such as the ones on this forum.