With a constructor, you can simulate arrays by making them from objects and property components. This may be useful if you want to run an array based script in a very old JavaScript implementation although these days that likelihood is diminishing rapidly.
This was necessary in JavaScript version 1.0. Numbered index locations within an Object object could simulate Array objects. Named items simply allocate the next available numbered entry.
Thankfully we don't have to do this anymore.
In Netscape 2.02 and MSIE 3.02 you can operate on existing arrays, but you cannot make a new one.
In Netscape 2.02 the array length value does not work properly.
// Simulate an array with an Object object myArray = new Object(); myArray[0] = "One"; myArray[1] = "Two"; // Simulate an array with a constructor function SimArray(aSize) { this.length = aSize; for(var index = 0; index<aSize; index++) { this[index] = 0; } return this; } // Now make a simulated array myArray = new SimArray(12);
See also: | Array(), Cast operator, Constructor function |
Prev | Home | Next |
Array.valueOf() | Up | ASCII |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |