私は非常にjavascriptで新しいです。私はcodepen.ioでいくつかのjavascriptプロジェクトを学びます。私はポンJS実装を発見した。私はそれを把握できない何かを見つけた。私はそれはそれはいくつかの変数を作るためにthis.
を使用する理由奇妙な部分の書き込みJSオブジェクト
var Game = {
initialize: function() {
this.canvas = document.querySelector('canvas');
this.context = this.canvas.getContext('2d');
this.canvas.width = 1400;
this.canvas.height = 1000;
this.canvas.style.width = (this.canvas.width/2) + 'px';
this.canvas.style.height = (this.canvas.height/2) + 'px';
this.player = Paddle.new.call(this, 'left');
this.paddle = Paddle.new.call(this, 'right');
this.ball = Ball.new.call(this);
this.paddle.speed = 8;
this.running = this.over = false;
this.turn = this.paddle;
this.timer = this.round = 0;
this.color = '#2c3e50';
Pong.menu();
Pong.listen();
}, //there are another properties
私の質問だものの種類がわからないので。 var
を使用しないのはなぜですか?私は約this.
の構文を見つけるので、私はそれらの説明に関連付けることはできません。 このコード行を理解するのを手伝ってください。ここ
はcodepenです:https://codepen.io/gdube/pen/JybxxZ?editors=1010
もし私が間違っていないなら、私はオブジェクトを参照してデータを保存する必要があります。それでは、var?あなたの簡単な説明を感謝します。良いことでした:) –
@hasby fahrudin関数内でただアクセス可能な値を格納するために変数(内部関数)を使用し、後から簡単に削除することができます。 –