Created
January 1, 2011 22:51
-
-
Save nzakas/762069 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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"; |
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.
lol @timdown...
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.
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.
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
Was the arguments object available back then? Depending, you could have done something like this no?