diff --git a/core/block.js b/core/block.js index 8bc08aeff..315a4d83c 100644 --- a/core/block.js +++ b/core/block.js @@ -454,13 +454,7 @@ Blockly.Block.prototype.setParent = function(newParent) { } if (this.parentBlock_) { // Remove this block from the old parent's child list. - var children = this.parentBlock_.childBlocks_; - for (var child, x = 0; child = children[x]; x++) { - if (child == this) { - children.splice(x, 1); - break; - } - } + goog.array.remove(this.parentBlock_.childBlocks_, this); // Disconnect from superior blocks. if (this.previousConnection && this.previousConnection.isConnected()) { diff --git a/core/events.js b/core/events.js index 1d1e2b70e..38e09ec4f 100644 --- a/core/events.js +++ b/core/events.js @@ -26,6 +26,7 @@ goog.provide('Blockly.Events'); +goog.require('goog.array'); goog.require('goog.math.Coordinate'); diff --git a/core/workspace.js b/core/workspace.js index a8e97c04b..a3a72e1b6 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -26,6 +26,7 @@ goog.provide('Blockly.Workspace'); +goog.require('goog.array'); goog.require('goog.math'); @@ -136,15 +137,7 @@ Blockly.Workspace.prototype.addTopBlock = function(block) { * @param {!Blockly.Block} block Block to remove. */ Blockly.Workspace.prototype.removeTopBlock = function(block) { - var found = false; - for (var child, i = 0; child = this.topBlocks_[i]; i++) { - if (child == block) { - this.topBlocks_.splice(i, 1); - found = true; - break; - } - } - if (!found) { + if (!goog.array.remove(this.topBlocks_, block)) { throw 'Block not present in workspace\'s list of top-most blocks.'; } }; @@ -444,10 +437,7 @@ Blockly.Workspace.prototype.addChangeListener = function(func) { * @param {Function} func Function to stop calling. */ Blockly.Workspace.prototype.removeChangeListener = function(func) { - var i = this.listeners_.indexOf(func); - if (i != -1) { - this.listeners_.splice(i, 1); - } + goog.array.remove(this.listeners_, func); }; /**