xxxxxxxxxx
43
// This class is not defined inside any function
class Circle
{
constructor(x, y)
{
this.x = x;
this.y = y;
}
}
function setup()
{
createCanvas(400, 400);
// Here is a hypothetical class that you wouldn't
// want to use that IS defined inside a function
class ExampleClass
{
constructor(x, y, whatever)
{
this.x = x;
this.y = y;
this.whatever = whatever;
}
}
// You can only create instances of ExampleClass
// inside the setup function
let example = new ExampleClass(1, 2, 3);
}
function draw()
{
background(220);
// You cannot create an instance of ExampleClass
// here, because this is a different scope from
// where the class was defined
let thisWontWork = new ExampleClass(4, 5, 6);
}