typeof null

Brendan Eich brendan at mozilla.com
Thu May 10 17:00:10 PDT 2012


Brendan Eich wrote:
> CoffeeScript has foo?.bar ... and foo.baz?(...) in lieu of
>
>   if (foo != null) foo.bar ...
>
> and
>
>   if (foo.baz != null) foo.baz(...)
>

Correction: the ?( operator compiles like so:

$ echo 'foo={};foo.baz?()' > /tmp/foo2.cs
$ ./bin/coffee -p !$
./bin/coffee -p /tmp/foo2.cs
(function() {
   var foo;

   foo = {};

   if (typeof foo.baz === "function") {
     foo.baz();
   }

}).call(this);

/be


More information about the es-discuss mailing list