Skip to content

Instantly share code, notes, and snippets.

@timaschew
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timaschew/9519475 to your computer and use it in GitHub Desktop.
Save timaschew/9519475 to your computer and use it in GitHub Desktop.
demo snippest of js2coffee talk at Berlin Node.js Meetup #3 - 2014-03-12 - try it out on http://js2coffee.org
// buggy when switch multiple times (js2coffee, coffee2js, js2coffee, ...)
foo = "bar"
// avoid the bug
main.foo = "bar";
// example for variable shadowing
var x = 0;
main.f = function(err, res) {
var x = 1;
};
// existence operator
if (main.foo != null) {
qux();
}
// inversible operators
if (foo && bar !== true || anything()) {
qux();
} else {
baz();
}
// show later in the slides (ternary operator) how this would be converted with js2coffee
main.foo = boolVal ? "yes" : "no";
// pretty print for complex object structures
main.x = {
foo: 1,
bar: 2,
nested: {
foo: 3,
bar: 4
},
array: [
1, 2, {
foo: 1
}, {
bar: 2
}
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment