I know the universal way of changing an array's size is to use .push().
However, today I saw a piece of code in angularJS that does something like this:
var service = {
pages: [],
doSmth: doSmth
};
doSmth();
function doSmth() {
service.pages[1] = "abc";
service.pages[5] = "def";
}
I ran the debugger on the browser and found that before doSmth() is called, pages[1] is undefined, but after that, pages[1] is assigned the value without any error.
How is this possible?
function doSmthis hoistedpushfunction is just a convenience to add an element tomyarray[myarray.length]