I’ve come across two ways of defining classes in p5.js.
The first: https://editor.p5js.org/femkeblanco/sketches/Vycw0YkNr
The second: https://editor.p5js.org/femkeblanco/sketches/YXi8pCrRQ
I presume the second way, which I came across in the book “Getting Started with p5.js”, is legacy. Is that correct?
My main question is the following:
I cannot declare and create an object in one line at the top using the first way: https://editor.p5js.org/femkeblanco/sketches/f7xH0mqRX
I have to create the object in setup(): https://editor.p5js.org/femkeblanco/sketches/Vycw0YkNr
But I can declare and create an object in one line at the top using the second way: https://editor.p5js.org/femkeblanco/sketches/YXi8pCrRQ
Why, why and why?
Your help is appreciated and thanks in advance.