所以我对这个p5js脚本有点麻烦。我得到一个TypeError,说“this.randomGenes不是一个函数”,但它看起来像一个我......我不明白错误来自哪里。它的拼写都是正确的,所有的分号都在那里,所有的括号都是关闭的,所有的括号都是。这个错误根本不会在我身上突出。'this.randomGenes'不是一个函数吗?
function DNA(genes) {
this.maxWeight = 25;
this.maxSpeed = 25;
if (genes) {
this.genes = genes;
} else {
this.genes = []; // weight, position, maxspeed, rgba
this.randomGenes();
}
this.randomGenes = function() {
this.genes[0] = random(this.maxWeight);
this.genes[1] = [random(height), random(width)];
this.genes[2] = random(this.maxSpeed);
this.genes[3] = [random(255), random(255), random(255), random(255)];
}
}
读码顺序:)在点,在那里你叫它,它尚未确定。 – qqilihq
'this'默认的作用范围是'function' –
你在哪里调用方法? –