I needed an array that could hold different object types and thought I would need to use some form of inheritance but then realized it already works by default in Javascript:
var someArray = [];
someArray.push("Hello World");
someArray.push(12);
someArray.push(false);
alert(someArray.pop());
alert(someArray.pop());
alert(someArray.pop());
Seems to work in JSFiddle. This may be a stupid question but is there anything wrong with doing something like this? In my background with C, C++, C#, VB .NET, etc. arrays need to be of a single type so this sort of thing seems magic to me. Is this sort of thing okay to do or will it only lead to bugs and hair-pulling?
Arrays are not strongly typed in javascript, so there’s no problem…