2
HTML 5 캔버스 용 입자 시스템의 초기 단계에서 즉각적인 문제가 발생합니다. 내 Particle
클래스 객체의 속성을 검색하려고하면 undefined
을 반환하고 이유를 파악할 수 없습니다!자바에서 객체 속성이 'undefined'를 반환합니다.
class Particle {
contructor(context, width, height) {
this.x = width/2;
this.y = height/2;
this.radius = Math.random() * 5 + 5;
}
};
var App = {
canvas: document.getElementById('canvas'),
ctx: canvas.getContext('2d'),
initialize: function() {
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
},
draw: function() {
var P = new Particle(this.ctx, this.canvas.width, this.canvas.height);
alert(P.x); // Why does this return undefined?
this.ctx.beginPath();
this.ctx.arc(P.x,P.y,P.radius,0,2*Math.PI);
this.ctx.stroke()
}
};
App.initialize();
App.draw();
맞춤법 오류를 말하는 빨간색 밑줄을 볼 때까지이 모든 것을 알아 내려고했습니다. 그것은 컨스트럭터가 아닌 생성자입니다 – Tremmillicious