Proxy Array part3
Attempts to fix
JavaScript
var target = ['hello', 'world'];
var handler = {
set : function (target, property, value, receiver) {
console.log("set", property, value);
target[property] = value;
},
get : function (target, property) {
if(property == 'length') {
return target.length;
}
},
deleteProperty: function (oTarget, sKey) {
console.log('opa')
},
};
var proxy = new Proxy(target, handler);
// set the first element to 'bye'
// proxy[0] = 'bye';
delete proxy
// now prints out '2', the correct length
console.log(proxy.length);
// foreach fails silently, unless you add a get() to the handler else
// you get an error complaining that the proxy does not have a forEach function!