On Tue, Jun 19, 2012 at 1:34 PM, Jeremy Ashkenas <[email protected]>wrote:

> Allen asks about when you would want to write `foo?.bar()`
>
> ... the only use case I can think of is when `foo` may or may not be
> defined, and you know that if it *is* defined, it's going to have a `bar`
> method on it, and if it *is* defined, you want to call `bar` for its side
> effects. A bit far fetched.
>

It doesn't seem that far-fetched to me -- I seem to constantly write things
like this in Java:

String name = (person != null) ? person.getName() : null;

IIUC, that could just be written as String name = person?.getName() if this
operator were avaialble.

Maybe you are saying that you don't want to have rigid class structures in
JS, but it seems reasonable that if you know person is of type Person it is
supposed to have a getName method on it.

-- 
John A. Tamplin
Software Engineer (GWT), Google
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to