From 1ebb736a2aa5c19196c93a6f5d947fea43c0ad29 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 6 Jun 2018 09:33:23 -0400 Subject: [PATCH] Check specifically for number in optional property --- src/sprites/rendered-target.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 739a813a4..4d051114b 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -488,10 +488,10 @@ class RenderedTarget extends Target { * @param {?int} index Index at which to add costume */ addCostume (costumeObject, index) { - if (typeof index === 'undefined') { - this.sprite.addCostumeAt(costumeObject, this.sprite.costumes.length); - } else { + if (typeof index === 'number' && !isNaN(index)) { this.sprite.addCostumeAt(costumeObject, index); + } else { + this.sprite.addCostumeAt(costumeObject, this.sprite.costumes.length); } } @@ -551,10 +551,10 @@ class RenderedTarget extends Target { addSound (soundObject, index) { const usedNames = this.sprite.sounds.map(sound => sound.name); soundObject.name = StringUtil.unusedName(soundObject.name, usedNames); - if (typeof index === 'undefined') { - this.sprite.sounds.push(soundObject); - } else { + if (typeof index === 'number' && !isNaN(index)) { this.sprite.sounds.splice(index, 0, soundObject); + } else { + this.sprite.sounds.push(soundObject); } }