Getter/setter on javascript array?
Posted
by Martin Hansen
on Stack Overflow
See other posts from Stack Overflow
or by Martin Hansen
Published on 2010-03-15T17:39:15Z
Indexed on
2010/03/15
17:39 UTC
Read the original article
Hit count: 443
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; }); };
© Stack Overflow or respective owner