Create null objects properly.

new Object(null) doesn’t do anything, that’s just broken.
And the for loop with keys is silly.
This commit is contained in:
Neil Fraser
2019-07-13 00:15:55 -07:00
committed by Neil Fraser
parent bbb6e03801
commit 2ac3447383
2 changed files with 5 additions and 6 deletions

View File

@@ -34,4 +34,4 @@ goog.provide('Blockly.Blocks');
* A mapping of block type names to block prototype objects.
* @type {!Object.<string,Object>}
*/
Blockly.Blocks = new Object(null);
Blockly.Blocks = Object.create(null);

View File

@@ -48,7 +48,7 @@ Blockly.VariableMap = function(workspace) {
* @type {!Object.<string, !Array.<Blockly.VariableModel>>}
* @private
*/
this.variableMap_ = {};
this.variableMap_ = Object.create(null);
/**
* The workspace this map belongs to.
@@ -61,7 +61,7 @@ Blockly.VariableMap = function(workspace) {
* Clear the variable map.
*/
Blockly.VariableMap.prototype.clear = function() {
this.variableMap_ = new Object(null);
this.variableMap_ = Object.create(null);
};
/* Begin functions for renaming variables. */
@@ -380,9 +380,8 @@ Blockly.VariableMap.prototype.getVariableTypes = function(ws) {
*/
Blockly.VariableMap.prototype.getAllVariables = function() {
var all_variables = [];
var keys = Object.keys(this.variableMap_);
for (var i = 0; i < keys.length; i++ ) {
all_variables = all_variables.concat(this.variableMap_[keys[i]]);
for (var key in this.variableMap_) {
all_variables = all_variables.concat(this.variableMap_[key]);
}
return all_variables;
};