Existential operator (was: ||= is much needed?)
jat at google.com
Wed Jun 20 12:51:05 PDT 2012
On Wed, Jun 20, 2012 at 12:47 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com>wrote:
> yes, but in a static Java-like language such as for you example above, the
> existence of person implies the existence of the getName method. The JS
> equivalent would likely be something like:
Is it really rare to write JS code that assumes objects passed to it have
an expected structure? Obviously, you don't have to, but when I have seen
object-oriented code written in JS it tends to make such assumptions.
If I write something that takes either null or a person object, I assume if
it isn't null it really is a person object and I don't write checks to
verify it. If someone passes something that doesn't have getName on it to
my method, I am perfectly fine with it blowing up. When I expect that it
might be null/undefined, then I have to write a bunch of boilerplate to
deal with that, and ?. allows removing that boilerplate.
John A. Tamplin
Software Engineer (GWT), Google
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss