Skip to content

Instantly share code, notes, and snippets.

@weepy
Created April 17, 2011 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weepy/923899 to your computer and use it in GitHub Desktop.
Save weepy/923899 to your computer and use it in GitHub Desktop.
Exploring a exists operator for Kaffeine
/* do we want
a?.b => a && a.b // minimal code created
a?.b => a != null && a.b // we get not null comparison - perhaps a sweet spot
a?.b => (typeof a != "undefined" && a != null) && a.b // CS style - makes messy looking JS?
--- ?? operator
a?? => (typeof a != "undefined") // interesting - probably not useful ?
*/
compiles:
a?
to:
a != null
compiles:
a?.b
to:
(a != null) && a.b
compiles:
a()?.b
var _x; _x = a(); _x != null && _x.b
@akidee
Copy link

akidee commented Apr 17, 2011

CS is doing it correctly (a != null). The ? operator is mainly existing to prohibit errors that only occur when you try to access properties of null or undefined. Every other expression is a kind of object.
false.toString()
should be allowed.

@weepy
Copy link
Author

weepy commented Apr 17, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment