Coffee script

  • 201 views
Uploaded on

 

More in: Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
201
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. CoffeeScript: JavaScript onSteroids By Jordan Dichev
  • 2. CoffeeScriptis • “A littlelanguangethat compiles into JavaScript” • Easiertoreadandwritethan JavaScript • SyntacticallyclosetoRubyand Python • Easytointegratewithexistingcode • Just JavaScript afterall
  • 3. Main Features • Significant whitespace and highly expressive • Bound functional literal and class sugar for prototypes • Loop, comprehensions and both • An existential operator • Splats (variadic parameters) • Default Parameters • Heredocs, heregexes • Automatic lexical scoping
  • 4. Functions square = (x) ->x * x (input arguments) -> output definition var square = function(x) { return x * x; }
  • 5. Literals guys = ['barry', 'larry', 'harry'] console.log guys[0] elements = hydrogen = 1 silicon = 14 uranium = 92 console.logelements.silicon
  • 6. Literals var elements, guys; guys = ['barry', 'larry', 'harry']; console.log(guys[0]); elements = { hydrogen: 1, silicon: 14, uranium: 92 }; console.log(elements.silicon);
  • 7. Whitespace today = 'tuesday' if today is 'tuesday' console.log 'UXEG' else console.log 'noop'
  • 8. Whitespace var today; today = 'tuesday'; if (today === 'tuesday') { console.log('UXEG'); } else { console.log('noop'); }
  • 9. Loops and comprehensions list = ['a', 'b', 'c'] console.log letter for letter in list process = good: 'good' bad: 'bad' console.log name for name of process console.logi for i in [0..10]
  • 10. List comprehensions vari, letter, list, name, process, _i, _j, _len; list = ['a', 'b', 'c']; for (_i = 0, _len = list.length; _i< _len; _i++) { letter = list[_i]; console.log(letter); } process = { good: 'good', bad: 'bad’ }; for (name in process) { console.log(name); } for (i = _j = 0; _j<= 10; i = ++_j) { console.log(i); }
  • 11. Existential operator person = name: 'John Doe' age: 28 console.logperson.name.length console.logperson.non?.existent.property console.logperson.name.reverse?()
  • 12. Existential operator varperson, _base, _ref; person = { name: 'John Doe', age: 28 }; console.log(person.name.length); console.log((_ref = person.non) != null ? _ref.existent.property : void 0); console.log(typeof (_base = person.name).reverse === "function" ? _base.reverse() : void 0);
  • 13. Classes class Message show: -> console.log 'Foo' class BarMessage extends Message show: -> console.log 'Bar’ new BarMessage().show()
  • 14. Conditionals if a console.log "a is true" else console.log "a is false” console.log "a is false" unless a
  • 15. Scope a = 'A' myFunc = -> a = 'AAA' b = 'B'
  • 16. Scope (function() { var a, myFunc; a = 'A’; myFunc = function() { varb; a = 'AAA'; return b = 'B'; }; }).call(this);
  • 17. String Interpolation name = "John Doe" console.log "Hello #{name}" console.log 'Hello #{name}'
  • 18. String Interpolation var name; name = "John Doe"; console.log("Hello " + name); console.log('Hello #{name}');
  • 19. Building coffee – a command line tool cake – a simple build tool coffee -w -o lib/ -jmergedSource.js-csrc/ -w – to watch for changes while we write -o – to specify output location -j – to merge all files into one -c – to specify input location