3-2-operators.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Operators
  3. ---------
  4. CoffeScript JavaScript
  5. == is ===
  6. != isnt !==
  7. not !
  8. and &&
  9. or ||
  10. true yes on true
  11. false no off false
  12. */
  13. var Decaf, addCaffeine, base, base1, base2, coffee, cupsOfCoffee, level, message, paid, pour;
  14. paid = coffee = pour = function() {};
  15. if (paid() && coffee() === true) {
  16. pour();
  17. }
  18. addCaffeine = Decaf = function() {};
  19. if (!Decaf()) {
  20. addCaffeine();
  21. }
  22. if (!Decaf()) {
  23. addCaffeine();
  24. }
  25. // Combined range checks
  26. level = 4;
  27. if ((2 < level && level < 5)) {
  28. alert("In range");
  29. }
  30. // Functional switch.
  31. message = (function() {
  32. switch (cupsOfCoffee) {
  33. case 0:
  34. return 'Asleep';
  35. case 1:
  36. return 'Eyes open';
  37. case 2:
  38. return 'Buzzed';
  39. default:
  40. return 'Dangerous';
  41. }
  42. })();
  43. // Existential check: not undefined and not null.
  44. if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
  45. alert('Exists');
  46. }
  47. if (typeof cupsOfCoffee !== "undefined" && cupsOfCoffee !== null) {
  48. alert('Exists');
  49. }
  50. // Not strictly identical to the two shorter forms below.
  51. if (typeof cupsOfCoffee === "undefined" || cupsOfCoffee === null) {
  52. cupsOfCoffee = 0;
  53. }
  54. if (cupsOfCoffee == null) {
  55. cupsOfCoffee = 0;
  56. }
  57. if (cupsOfCoffee == null) {
  58. cupsOfCoffee = 0;
  59. }
  60. if (typeof coffeePot !== "undefined" && coffeePot !== null) {
  61. coffeePot.brew();
  62. }
  63. if (typeof vehicle.start_engine === "function") {
  64. if (typeof (base = vehicle.start_engine()).shift_gear === "function") {
  65. if (typeof (base1 = base.shift_gear()).crank === "function") {
  66. if (typeof (base2 = base1.crank()).press_gas === "function") {
  67. base2.press_gas();
  68. }
  69. }
  70. }
  71. }
  72. //# sourceMappingURL=3-2-operators.js.map