Skip to content

Instantly share code, notes, and snippets.

@tricknotes
Created May 10, 2011 08:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tricknotes/964079 to your computer and use it in GitHub Desktop.
Save tricknotes/964079 to your computer and use it in GitHub Desktop.
CoffeeScriptで3項演算子風に書くと、コンパイルされてできあがるJavaScript
// a ? b : c
if (typeof a !== "undefined" && a !== null) {
a;
} else {
({b: c});
}
// if a then b else c
if (a) {
b;
} else {
c;
}
// d = a ? b : c
d = typeof a !== "undefined" && a !== null ? a : { b: c }
// d = if a then b else c
d = a ? b : c;
@tricknotes
Copy link
Author

CoffeeScriptで3項演算子っぽく書きたい時は、if 〜 then 〜 else 〜 を使って書くのがよさそう

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