move misc to js/ui
This commit is contained in:
parent
594ac2b012
commit
4a48deeb2c
18 changed files with 4 additions and 4 deletions
19
1-js/99-js-misc/01-proxy/02-array-negative/solution.md
Normal file
19
1-js/99-js-misc/01-proxy/02-array-negative/solution.md
Normal 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
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue