0
키를 기반으로 동적으로 그리기 함수를 호출하려고합니다.정적 함수의 해시 반환 빈 개체입니다.
renderFunctions를 로그 아웃하면 빈 Object {}로 표시됩니다.
'ship'과 'ball'키가있는 내부 기능이 필요합니다.
class Render {
static renderFunctions() {
return {
'ship': this.drawShip,
'ball': this.drawBall
};
}
static render(key, ls, context, portal) {
let renderFns = this.renderFunctions();
console.log(renderFns);
}
static drawShip(ctx, p, t) {
p.drawRect(ctx, t.x - 5, t.y - 100, 10, 100, t.teamColor);
}
static drawBall(ctx, p, t) {
ctx.arc(t.x, t.y, 7, 0, 2 * Math.PI, false);
ctx.fillStyle = t.teamColor;
ctx.fill();
}
}
왜 내 기능이 표시되지 않는?
나는 그것을 시도했다. 여전히 같은 오류가 발생합니다. – quantumpotato
@quantumpotato 콘솔에서'Object {}'를 클릭하면, 여러분의 기능을 볼 수 있습니다. –
그리고 renderFns [key] (...)를 사용하여 직접 호출 할 수 있습니까? – quantumpotato