関数のインスタンスが互いにプロパティを継承するのを止める方法はありますか? Javascripts プロトタイプ オブジェクトに関する記事を読んでいて、以下を読みました。
「プロトタイプが「ライブ」であることに注意することが重要です。JavaScript ではオブジェクトは参照によって渡されるため、新しいオブジェクト インスタンスごとにプロトタイプがコピーされるわけではありません。これは実際にはどういう意味ですか?いつでも、すべてのオブジェクト (変更前に作成されたものも含む) が変更を継承します。」
すべてのオブジェクトが更新されないようにする方法はありますか? 各インスタンスのプロパティを一意に保ちたいと思います。そうでない場合、プロパティを関数に割り当てる他の方法はありますか? ここに私が取り組んでいるいくつかのコードがあります。three.js でアニメーション化されたスプライトを表示できますが、関数の新しいインスタンスを作成すると、インスタンスは新しいインスタンスが呼び出すフレームにジャンプします。したがって、すべて同じフレームが表示されます。継承を有効にできるかどうかはわかりました。ずさんな場合は申し訳ありませんが、質問に必要のないものをたくさん削除しました。
function slowToStopFunc(texture, tilesHoriz, tilesVert, numTiles, tileDispDuration) {
this.tilesHorizontal = tilesHoriz;
this.tilesVertical = tilesVert;
this.numberOfTiles = numTiles;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 1 / this.tilesHorizontal, 1 / this.tilesVertical );
this.tileDisplayDuration = tileDispDuration;
this.currentDisplayTime = 0;
this.currentTile = 3;
this.update3 = function( milliSec3 ) {
this.currentDisplayTime += milliSec3;
while (this.currentDisplayTime > this.tileDisplayDuration && adjustSpeed <= 2)
{
if (this.currentTile >= -1 && this.currentTile <= 14) {
this.currentTile++;
}
}
var currentColumn = this.currentTile % this.tilesHorizontal;
texture.offset.x = currentColumn / this.tilesHorizontal;
var currentRow = Math.floor( this.currentTile / this.tilesHorizontal );
texture.offset.y = currentRow / this.tilesVertical;
}
}