Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CoffeeScript and Less

Avatar for Daniel Shearmur Daniel Shearmur
April 18, 2013
120

CoffeeScript and Less

Avatar for Daniel Shearmur

Daniel Shearmur

April 18, 2013
Tweet

Transcript

  1. BAD

  2. functions square = (x) -> x * x cube =

    (x) -> square(x) * x cube 4 # same as cube(4)
  3. loops eat food for food in ['toast', 'cheese', 'wine'] for

    el in document.querySelectorAll('h2') el.style.display = "none" for key, val of window console.log key, val
  4. conditionals if happy and knowsIt clapHands() else showIt() action =

    if isHidden then "show" else "hide" doThings() unless x == 10
  5. classes class Animal constructor: (@name) -> move: (meters) -> alert

    @name + " moved #{meters}m." class Snake extends Animal move: -> alert "Slithering..." super 5
  6. mixins .bordered(@colour: black) { border-top: dotted 1px @colour; border-bottom: solid

    2px @colour; } #menu a { color: #111; .bordered; } .post a { color: red; .bordered(pink); }