From 4b5e7a57a57aa14bfba6dc0bc2e616a7c519dc44 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 19 Apr 2017 08:53:07 -0400 Subject: [PATCH] Fix binding issues --- src/import/load-sound.js | 2 +- src/virtual-machine.js | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/import/load-sound.js b/src/import/load-sound.js index e01f0b4d..e50077c4 100644 --- a/src/import/load-sound.js +++ b/src/import/load-sound.js @@ -7,7 +7,7 @@ var log = require('../util/log'); * @property {string} md5 - the MD5 and extension of the sound to be loaded. * @property {Buffer} data - sound data will be written here once loaded. * @param {!Runtime} runtime - Scratch runtime, used to access the storage module. - * @returns {!Promise} - a promise which will resolves to the sound when ready. + * @returns {!Promise} - a promise which will resolve to the sound when ready. */ var loadSound = function (sound, runtime) { if (!runtime.storage) { diff --git a/src/virtual-machine.js b/src/virtual-machine.js index f5b25b90..ca0edc9f 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -153,24 +153,23 @@ VirtualMachine.prototype.postIOData = function (device, data) { * @return {!Promise} Promise that resolves after targets are installed. */ VirtualMachine.prototype.loadProject = function (json) { - var that = this; // @todo: Handle other formats, e.g., Scratch 1.4, Scratch 3.0. return sb2import(json, this.runtime).then(function (targets) { - that.clear(); + this.clear(); for (var n = 0; n < targets.length; n++) { if (targets[n] !== null) { - that.runtime.targets.push(targets[n]); + this.runtime.targets.push(targets[n]); targets[n].updateAllDrawableProperties(); } } // Select the first target for editing, e.g., the first sprite. - that.editingTarget = that.runtime.targets[1]; + this.editingTarget = this.runtime.targets[1]; // Update the VM user's knowledge of targets and blocks on the workspace. - that.emitTargetsUpdate(); - that.emitWorkspaceUpdate(); - that.runtime.setEditingTarget(that.editingTarget); - }); + this.emitTargetsUpdate(); + this.emitWorkspaceUpdate(); + this.runtime.setEditingTarget(this.editingTarget); + }.bind(this)); }; /** @@ -195,15 +194,14 @@ VirtualMachine.prototype.downloadProjectId = function (id) { */ VirtualMachine.prototype.addSprite2 = function (json) { // Select new sprite. - var that = this; sb2import(json, this.runtime, true).then(function (targets) { - that.runtime.targets.push(targets[0]); - that.editingTarget = targets[0]; + this.runtime.targets.push(targets[0]); + this.editingTarget = targets[0]; // Update the VM user's knowledge of targets and blocks on the workspace. - that.emitTargetsUpdate(); - that.emitWorkspaceUpdate(); - that.runtime.setEditingTarget(that.editingTarget); - }); + this.emitTargetsUpdate(); + this.emitWorkspaceUpdate(); + this.runtime.setEditingTarget(this.editingTarget); + }.bind(this)); }; /**