Created
April 17, 2011 09:50
-
-
Save weepy/923899 to your computer and use it in GitHub Desktop.
Exploring a exists operator for Kaffeine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 | |
Yes that makes sense. The point is I am proposing to not check for
undefined variables. Seems like an edge case.
…On 17 Apr 2011, at 14:58, akidee ***@***.*** wrote:
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.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/923899
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.