ich eine ES6 Klasse haben, die wie folgt definiert ist hat und ein paar Funktionen:ES6 objekt.methode ist keine Funktion
class Cell{
constructor(i,j){
this.i = i;
this.j = j;
this.alive = false;
this.survives = false; //Made so not to change alive variabe mid-loop, also controls birthing of new cells
}
update(grid){
//Decide if this.survives is true or not
}
render(size){
//Draw's a rectangle in the cell's location in a color based on this.alive
}
}
Und eine main.js Datei:
const h = 800; //Height
const w = 800; //Width
const s = 80; //Size of squares
const rows = Math.floor(h/s);
const cols = Math.floor(w/s);
let cells = new Array(cols);
let isActive = false;
//A p5 function that is called once when the page is sketch is loaded
function setup() {
createCanvas(w, h);
for(let i = 0; i < cols; i++){
cells[i] = new Array(rows);
for(let j = 0; j < rows; j++){
cells[i][j] = new Cell(i, j);
}
}
}
//A p5 function that is called every frame
function draw() {
for(i = 0; i < cols; i++){
for(j = 0; j < rows; j++){
if(isActive === true){
cells[i][j].update(cells);
if(cells[i][j].survives){
cells[i][j] = true;
}else{
cells[i][j] = false;
}
}
cells[i][j].render(s);
}
}
}
Als ich Öffne die Webseite, die alles normal gerendert wird, aber wenn ich isActive auf true über die Chrome-Konsole einstelle bekomme ich folgende Fehlermeldung:
Uncaught TypeError: Zellen [i] [j] .render ist keine Funktion
Ich habe darauf geachtet, Referenzen auf alles in index.html hinzuzufügen, ich mache nichts Besonderes mit require(). Es ist alles mit Script-Tags
Nun, die Werte 'true' und' false' nicht habe eine solche Methode in der Tat. – Bergi