Home Accessing a class function with array of objects
 I was coding in p5.js, and I noticed a problem that I couldn't pass. I have a class named "Boxes". I am already using the functions that "Boxes" have. But while I tried to use that functions apply to an array of objects, It didn't work. How can I fix this problem? class Boxes { constructor() { this.x; this.y; this.r=222; this.g=55; this.b=111; } show() { fill(this.r,this.g,this.b); rect(this.x,this.y,50,50); } }  For standard variable it works perfectly like this. var box1 = new Boxes(); box1.show(); // It works.  When I tried something different it doesn't work. The example below. var myboxes = [{'x':this.x, 'y':this.y}]; // That's OK :) myboxes.push({x:100, y:100}); // That's OK too :) myboxes[1].show(); // But. It gives an error :/  It says: "myboxes[1].show is not a function" Although I write the show() function, with parentheses. It says "myboxes[1].show is not a function" It works fine when I use box1.show(). How can I access the functions using an array of objects? Shall I try something else? What are you suggesting?