This is the weirdest thing I’ve ever encountered in my programming life.
self.walls = new Array();
self.walls = [];
console.log(self.walls); //Doesn't print an empty array, but an array that contains something
How is this possible? I set self.walls to an empty array in two ways, and it’s still full of objects! I’m using the latest version of Google Chrome.
Edit: also, this is the only console.log() in the entire script.
console.logdoes not store the state of the object at the time of calling.At a later point, you’ve overwritten the
self.wallsproperty, which is shown in the console.If you want to log the true state at the time of executing, you can serialize the object: