This commit is contained in:
Ilya Kantor 2019-06-12 22:37:45 +03:00
parent 726f08a179
commit 852b9bf581
20 changed files with 1074 additions and 20 deletions

View file

@ -0,0 +1,19 @@
```js run
let array = [1, 2, 3];
array = new Proxy(array, {
get(target, prop, receiver) {
if (prop < 0) {
// even if we access it like arr[1]
// prop is a string, so need to convert it to number
prop = +prop + target.length;
}
return Reflect.get(target, prop, receiver);
}
});
alert(array[-1]); // 3
alert(array[-2]); // 2
```