| MS Internet Explorer does not work with objects derived from Array() |
|
|
This is a javascript example of an object derived from Array():
function PaletteList(preselected) {
// the arguments after 'preselected' are palette names
var last = arguments.length - 1
for(var i=0; i < last; i++)
this[i] = arguments[i + 1]
this.name = 'palettes'
this.preselected = preselected
}
PaletteList.prototype = new Array
colourPalette = new PaletteList(1, 'spring', 'summer', 'autumn')
A reference like colourPalette[2] will cause an error if run in a script with MS Internet Explorer and you will find out that 'colourPalette' is empty.
|
||
| How it was solved |
|
|
The only way around is to internalise the array as shown here after:
function PaletteList(preselected) {
// the arguments after 'preselected' are palette names
var last = arguments.length - 1
this.option = new Array(last)
for(var i=0; i < last; i++)
this.option[i] = arguments[i + 1]
this.name = 'palettes'
this.preselected = preselected
}
now colourPalette.option[n] will find the data.
You have to avoid using PaletteList.prototype = new Array if you intend to add other properties to the object. |
||