Guest User

Untitled

a guest
Apr 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. # TODO: Think of a name for this crazy thing.
  2.  
  3. # Functions:
  4. square: x => x * x.
  5.  
  6. sum: x, y => x + y.
  7.  
  8. odd: x => x % 2 is 0.
  9.  
  10. even: x => x % 2 aint 0.
  11.  
  12. run_loop: =>
  13. fire_events( e => e.stopPropagation(). )
  14. listen()
  15. wait().
  16.  
  17. # Objects:
  18. object_literal: {one: 1, two: 2, three: 3}
  19.  
  20. multiline_object: {
  21. pi: 3.14159
  22. list: [1, 2, 3, 4]
  23. three: new Idea()
  24. inner_obj: {
  25. freedom: => _.freedom().
  26. }
  27. }
  28.  
  29. # Arrays:
  30. stooges : [{moe: 45}, {curly: 43}, {larry: 46}]
  31.  
  32. exponents : [x => x., x => x * x., x => x * x * x.]
  33.  
  34. # Conditionals and ternaries.
  35. if submarine.shields_up
  36. full_speed_ahead()
  37. fire_torpedos()
  38. else
  39. run_away().
  40.  
  41. eldest: if 25 > 21 then liz else marge.
  42.  
  43. decoration: medal_of_honor if war_hero
  44.  
  45. go_to_sleep() unless coffee
  46.  
  47. # Returning early:
  48. race: =>
  49. run()
  50. walk()
  51. crawl()
  52. if tired then return sleep().
  53. race().
  54.  
  55. # Conditional operators:
  56. good ||= evil
  57. wine &&= cheese
  58.  
  59. # Nested property access and calls.
  60. ((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position
  61.  
  62. a: b: c: 5
  63.  
  64. # Embedded JavaScript.
  65. callback(
  66. `function(e) { e.stop(); }`
  67. )
  68.  
  69. # Try/Catch/Finally/Throw.
  70. try
  71. all_hell_breaks_loose()
  72. dogs_and_cats_living_together()
  73. throw "up"
  74. catch error
  75. print( error )
  76. finally
  77. clean_up().
  78.  
  79. try all_hell_breaks_loose() catch error print(error) finally clean_up().
  80.  
  81. # While loops.
  82. while demand > supply
  83. sell()
  84. restock().
  85.  
  86. while supply > demand then buy().
  87.  
  88. # Unary operators.
  89. !!true
  90.  
  91. # Lexical scoping.
  92. a: 5
  93. change_a_and_set_b: =>
  94. a: 10
  95. b: 15.
  96. b: 20
  97.  
  98. # Array comprehensions.
  99. supper: food.capitalize() for food in ['toast', 'cheese', 'wine'].
  100.  
  101. drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] if even(i).
  102.  
  103. # Switch statements.
  104. switch day
  105. case "Tuesday" then eat_breakfast()
  106. case "Sunday" then go_to_church()
  107. case "Saturday" then go_to_the_park()
  108. case "Wednesday"
  109. eat_breakfast()
  110. go_to_work()
  111. eat_dinner()
  112. default go_to_work().
Add Comment
Please, Sign In to add comment