News for hackers. Stuff that matters.
Re:Proxy, a new JavaScript ES6 feature by techsin101 on Friday May 18, 2018 @04:18AM (#17099567)
This is another feature that goes into bucket "I'll never use" along generators
Re:Proxy, a new JavaScript ES6 feature by sametmax on Friday May 18, 2018 @04:37AM (#17099679)
Generators require a mind switch to be used regularly. And the browser is not the place where the most obvious use cases are, so it's harder to make your first steps here.

The easiest things to start using generators is to write sysadmin scripts that parse big files. Once you've done that, you get the memory benefit. Then the more you use it, the more you get the lazy evaluation benefit and you start using it elsewhere.

It's clearer in Python because:

- generators have there for ever

- we have unified way of iterating on things, and generators just work transparently

- you can start learning generators by just changing [] to () in your comprehension lists

So in JS it's much less obvious.

Re:Proxy, a new JavaScript ES6 feature by icc97 on Friday May 18, 2018 @06:52AM (#17100383)
Yeah, lazy evaluation is the big feature of generators. Given that it's such a powerful feature of Haskell it's definitely worth investigating them.
Re:Proxy, a new JavaScript ES6 feature by CapacitorSet on Friday May 18, 2018 @04:34AM (#17099666)
I agree it doesn't seem super useful, but it can be used to pull some semantic tricks. I used it in [Rebridge](https://github.com/CapacitorSet/rebridge/) to implement syntactic sugar for database access, so that accessing a property on an object translates transparently to a query, and I've seen it used to [allow for typos in property names](https://github.com/mathiasbynens/tpyo).
Re:Proxy, a new JavaScript ES6 feature by yashthakur on Friday May 18, 2018 @06:43AM (#17100339)
I especially liked the "construct" part as we can use it to take input from the users in frontend as a numbered value and then store it in the database with the currency format which can be later used to make the value visible with the currency in the frontend.
Re:Proxy, a new JavaScript ES6 feature by boubiyeah on Friday May 18, 2018 @05:11AM (#17099852)
It's such a niche feature. And only useful if you use mutative OO style. Also it gets a bit too much into the magic territory for me, this is hard to debug and reason about, even harder than getter/setters.
Re:Proxy, a new JavaScript ES6 feature by m_ke on Friday May 18, 2018 @08:15AM (#17100773)
It's a feature you'll probably end up using all the time without even noticing it.

I just wrote a class to keep track of changes to an object using proxies yesterday. That way you can pass an object to a form, modify it in place and then roll back if needed. Also makes it easy to get deltas and only post the updates to the backend.

Re:Proxy, a new JavaScript ES6 feature by augbog on Friday May 18, 2018 @04:28AM (#17099624)
Well technically if you use async / await, it's built on top of generators and promises.
Re:Proxy, a new JavaScript ES6 feature by romaniv on Friday May 18, 2018 @11:53AM (#17102433)
Proxies are a basic feature that should be a part of any OO language. Their usefulness ranges from "save yourself a lot of repetitive work" to "impossible to implement without".

Very simple real-life use case: factor out logging and move it outside of normal logic of the object.

Re:Proxy, a new JavaScript ES6 feature by maaaats on Friday May 18, 2018 @05:54AM (#17100097)
Here's a list of stuff proxies have been used for https://github.com/mikaelbr/proxy-fun