The article brings me thought about similar solution in javascript.
Of course, there is a serious lack of something like negative indexing (you need access with arr[arr.length -1])
But, proxies come to the rescue!
it's something like a wrapper object for your data give them superpowers. Let me show you a simple example with arrays:
arrProxy applies an internal method that gives an ability to do more with your objects.
the prop is always a string, so we need to convert it into a number.
Another caveat - In js ':' is the invalid syntax in this case so wrapping '::-2' in quotes as string
That's a really nice workaround to use slicing and negative indexes in JavaScript! I do wish sometimes that js array would be as neat to work with as python lists haha
Maybe someday :)
Generally, proxies are a really interesting way to enhance javascript objects and arrays and use them in a way we didn't even imagine what is possible :D
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The article brings me thought about similar solution in javascript.
Of course, there is a serious lack of something like negative indexing (you need access with
arr[arr.length -1]
)But, proxies come to the rescue!
it's something like a wrapper object for your data give them superpowers. Let me show you a simple example with arrays:
arrProxy
applies an internal method that gives an ability to do more with your objects.the prop is always a string, so we need to convert it into a number.
Another caveat - In js ':' is the invalid syntax in this case so wrapping '::-2' in quotes as string
More about proxy:
That's a really nice workaround to use slicing and negative indexes in JavaScript! I do wish sometimes that js array would be as neat to work with as python lists haha
Maybe someday :)
Generally, proxies are a really interesting way to enhance javascript objects and arrays and use them in a way we didn't even imagine what is possible :D