Skip to content

Instantly share code, notes, and snippets.

@nzakas
Created January 1, 2011 22:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nzakas/762069 to your computer and use it in GitHub Desktop.
Save nzakas/762069 to your computer and use it in GitHub Desktop.
/*
* Pre-ECMAScript 1, JavaScript didn't have native arrays.
* Those who needed them frequently used functions such as the following.
* Also note that there was no special "undefined" value.
*/
function makeArray(len){
var array = new Object();
array.length = len;
//initialize each item with null (empty placeholder)
for (var i=0; i < len; i++){
array[i] = null;
}
return array;
}
var colors = makeArray(4);
colors[0] = "red";
colors[1] = "blue";
colors[2] = "green";
colors[3] = "black";
@timdown
Copy link

timdown commented Jan 7, 2011

This is rubbish. I remember using Arrays in the late 90s in Netscape 3. A little research shows that Arrays were in the first version of the ECMAScript spec released in 1997.

@nzakas
Copy link
Author

nzakas commented Jan 7, 2011

Good call, that's a typo in the gist, it should be pre-ECMAScript 1. The fact that you're missing is that JavaScript was implemented in Netscape 2, before ECMA-262 existed. There were no arrays in that version.

@timdown
Copy link

timdown commented Jan 7, 2011

Sorry, I was overly aggressive in my previous comment. I do remember being aware that JavaScript had once not had Arrays, so that only leaves Netscape 2, which was out of the picture by the time I started JavaScript in 1998.

@kevzettler
Copy link

Was the arguments object available back then? Depending, you could have done something like this no?

var Array0 = function(){
    var array = {};
    for (var i = 0; i < arguments.length; i++){
      array[i] = arguments[i];   
    }

  return array;
}

var new_array = Array0(3,4,5,'wot','okay');
new_array[0]; //3
new_array[1]; //4
new_array[2]; //5
new_array[3]; // 'wot'
new_array[4]; // 'okay'

@timdown
Copy link

timdown commented Jan 10, 2011

JavaScript 1.1 introduced the arguments object. JavaScript 1.0 did not have it. I believe the first ECMA standard was based on JavaScript 1.2 that appeared in Netscape 4, but I couldn't swear to it.

@ghepting
Copy link

lol @timdown...

@timdown
Copy link

timdown commented Mar 14, 2013

A couple of years of learning to be slower to judge and generally nicer on the internet makes me a bit shocked at my efforts here. Sorry again, Nicholas.

@garethmaybery
Copy link

Nicholas, thank you for this! Just started coding in JavaScript and this piece of code really helped me solve my problem I was having with creating multiple arrays with a function.

@artidataio
Copy link

It is 2023, you can write colors this way now:

let colors = ["red", "blue", "green", "black"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment