Open slorber opened 4 years ago
Thanks for opening! You're right, we do need better examples. Common uses I've seen are:
The examples in the readme were super contrived, just meant to give an example of the syntax. What I commonly want it for are to lazy init properties on class instances. And sometimes to initialize properties deeply owned by my instances.
Thanks for these examples.
Honestly these didn't really convince me much.
const list = name == 'children' ? children : props[name] || (props[name] = []);
const list = name == 'children' ? children : props[name] ||= []);
I'd say in both cases it's not very readable, and you can probably be rewritten it in a more understandable way that would not require logical assignment operators in the first place.
Hi, I saw on reddit that the very first example is not self explanatory. Not everyone is familiar with a || (a = b); kind of syntax. Maybe try something more universal like if else.
Hi,
@DanielRosenwasser suggested I open an issue here to discuss better examples.
https://twitter.com/drosenwasser/status/1245995703559532544
Currently exemples feels a bit bad to me, because they show potentially dangerous side-effectful functions
Here it's not harmful because the
example({ foo: 'foo' })
is passed a new option object everytime, but withexample(constantObject)
and having the constantObject being shared could be very dangerous, as it could somehow override default option values or things like that.I don't have a good example to suggest.
Could people that want the feature can come with beter real world code where this new proposal would actually improve the program.
I'm willing to get convinced by this proposal, and wanted to check examples for that, but it didn't really help so far (somehow, related to https://github.com/tc39/proposal-logical-assignment/issues/2)