Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

tricknotes commented May 10, 2011

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

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