Actualmente estoy tratando de entender los objetos JavaScript/TS y no entiendo exactamente cuándo funciona la palabra clave "esto". Por ejemplo: ¿Por qué funciona este código?:
updateValues: function(){ room.cellsVert = parseFloat(heightInput.value); room.cellsHoriz = parseFloat(widthInput.value); room.tileWidth = room.width / room.cellsHoriz; room.tileHeight = room.height / room.cellsVert; ctx.beginPath() ctx.fillStyle = "black"; ctx.fillRect(0, 0, room.width, room.height); ctx.stroke(); ctx.strokeStyle = "white"; for(let i = 0; i < room.cellsVert; i++) for(let j = 0; j < room.cellsHoriz; j++) { ctx.beginPath(); ctx.rect(room.tileWidth * j, room.tileHeight * i, room.tileWidth, room.tileHeight); ctx.stroke(); } }pero esto solo establece un montón de valores en 0/indefinido?:
updateValues: function(){ this.cellsVert = parseFloat(heightInput.value); this.cellsHoriz = parseFloat(widthInput.value); this.tileWidth = this.width / this.cellsHoriz; this.tileHeight = this.height / this.cellsVert; ctx.beginPath() ctx.fillStyle = "black"; ctx.fillRect(0, 0, this.width, this.height); ctx.stroke(); ctx.strokeStyle = "white"; for(let i = 0; i < this.cellsVert; i++) for(let j = 0; j < this.cellsHoriz; j++) { ctx.beginPath(); ctx.rect(this.tileWidth * j, this.tileHeight * i, this.tileWidth, this.tileHeight); ctx.stroke(); } }Sé que puede ser una pregunta tonta, pero agradecería alguna explicación. Gracias.