Image

Imageutil wrote in Imagejavascript

Define [] operator?

Is there a standard syntax for defining the [] operator for a given object? If so, what is it? Also, if the object already defines a [] operator, how may we preserve it so that we can call the old [] operator from our new [] operator?

For a project of a friend of mine, it would be convenient to redefine Array's [] operator to return Number.POSITIVE_INFINITY in the case that the value of a given index is undefined.

Alternatively, is there a standard way (or any way) of specifying a default value for "missing" elements in array literals. Ie, is there a way of specifying that executing v = [,1,,3] will leave v[0] == X and v[2] == X where X is some value of our choosing?

Thanks.