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
/* Extremely simple definition of a 2D array in Javascript. Javascript doesn't allow for a match-all getter so a length has to be defined. This defines the height or rows of the array but not the width; the width or columns is as big as you want it to be, sugar. For some odd reason, the __defineGetter__ doesn't send the name of the current "get" to the callback (which is silly in my opinion for situations exactly like these) so I had to convert the functions to strings. */ | |
var Array2D = function(l) { | |
if(!l) throw new Error("Please specify a length for your Array2D"); | |
this.arr = []; | |
this.definedLength = l; | |
for(var i = 0; i < l; i++) { | |
this.__defineGetter__(i, Function("var i = " + i + ";if(!this.arr[i]) this.arr[i] = [];return this.arr[i];")); | |
} |
NewerOlder