그래서이 p5js 스크립트로 약간의 문제가 있습니다. "this.randomGenes는 함수가 아닙니다"라고 말하는 TypeError가 발생합니다.하지만 나에게도 비슷합니다 ... 오류의 출처를 이해할 수 없습니다. 모든 철자가 올바른지, 모든 세미콜론이 있습니다. 모든 대괄호가 닫히고, 모든 괄호도 닫힙니다. 그 오류는 저에게 두드러지지 않습니다.'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'으로 범위가 정해졌습니다 –
어디에서 메서드를 호출할까요? –