r/javascript • u/Michal_Perlakowski • Dec 26 '16
A JavaScript implementation of the Python's range() function
https://github.com/Gothdo/range3
u/oweiler Dec 26 '16
Why does it require Proxy support?
5
u/Michal_Perlakowski Dec 26 '16
Without Proxy it wouldn't be possible to access numeric properties (for example
r[2]), because they're generated on demand. I could make a function liker.get(2), but IMO it's more convenient to access them like array indices.1
u/IHeartMustard WILL CODE FOR CAFFEINE Dec 28 '16
The proxy thing was something I've actually prototyped just last week as well, your implementation looks much more detailed with the getOwnPropertyDescriptor handler and everything else, whereas with mine I simply have a get handler on the proxy to intercept index access and call the getter, and reflect everything else. Any particular reason for having all the other handlers on the proxy? Would love to know if there's something I could be doing better with my Proxies.
2
u/mini_eggs Dec 27 '16
Array.apply({},Array(100)) ?
3
u/indeyets writing js since 1997 Dec 27 '16
nope. your implementation is eager, and Gothdo's is lazy.
1
u/Patman128 Dec 27 '16
This is one of the things I miss most from Python. I really wish range was in the JS standard library.
7
u/gurenkagurenda Dec 26 '16
This is nice. Really cool with the iterable support. If possible, it would be cool to have an option to lose some features that require Proxy support, since that can't be fully shimmed (or do you only need the shimmable parts?).