Getter/setter on javascript array?
- by Martin Hansen
Is there a way to get a get/set behaviour on an array? I imagine something like this:
var arr = ['one', 'two', 'three'];
var _arr = new Array();
for (var i=0; i < arr.length; i++) {
arr[i].defineGetter('value',
function(index) {
//Do something
return _arr[index];
});
arr[i].defineSetter('value',
function(index, val) {
//Do something
_arr[index] = val;
});
};