Possible Duplicate:
How would you overload the [] operator in javascript
Is it possible to overload the [] operator for arrays in Javascript?
For instance I would like to modify the behavior of the bracket so that when it accesses an index out of range it returns 0 instead of undedined
.
I know I could probably get away with something like this:
function get(array, i) {
return array[i] || 0;
}
But that's not really modifying the behavior of arrays the way I want.