Existential operator (was: ||= is much needed?)
allen at wirfs-brock.com
Tue Jun 19 09:44:34 PDT 2012
On Jun 19, 2012, at 2:30 AM, David Bruant wrote:
> What about a more generic operator that would be able to silently absorb any error?
> let greedy = obj.hints?.greedy;
> would become:
> let greedy = silent obj.hints.greedy;
A hazard with this approach is that it could silence a broader range of errors than the programmer intended. In the above example, the programmer's intent is probably just to not try to access greedy if hints doesn't exist. However, if greedy is an accessor property that throws your silent operator would also mask that throw (while ?. would not). It isn't clear that this would be desirable if the throw is an unexpected behavior.
More information about the es-discuss