-
-
Save hosam1696/14f61e6c4a938a4bea7df4a59e45b5b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const handler = { | |
| get(target, propKey, receiver) { | |
| if (/^_[0-9]+$/.test(propKey)) { | |
| const result = []; | |
| const first = Number(receiver); | |
| const last = Number(propKey.slice(1)); | |
| for (let i=first; i<=last; i++) { | |
| result.push(i); | |
| } | |
| return result; | |
| } | |
| return Reflect.get(target, propKey, receiver); | |
| } | |
| }; | |
| const proxy = new Proxy(Object.prototype, handler); | |
| Object.setPrototypeOf(Number.prototype, proxy); | |
| /* | |
| > 1 . _3 | |
| [ 1, 2, 3 ] | |
| > 11 . _14 | |
| [ 11, 12, 13, 14 ] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment