Coffee script
Upcoming SlideShare
Loading in...5
×
 

Coffee script

on

  • 344 views

 

Statistics

Views

Total Views
344
Views on SlideShare
344
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Coffee script Coffee script Presentation Transcript

    • CoffeeScript: JavaScript onSteroids By Jordan Dichev
    • CoffeeScriptis • “A littlelanguangethat compiles into JavaScript” • Easiertoreadandwritethan JavaScript • SyntacticallyclosetoRubyand Python • Easytointegratewithexistingcode • Just JavaScript afterall
    • 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
    • Functions square = (x) ->x * x (input arguments) -> output definition var square = function(x) { return x * x; }
    • Literals guys = ['barry', 'larry', 'harry'] console.log guys[0] elements = hydrogen = 1 silicon = 14 uranium = 92 console.logelements.silicon
    • Literals var elements, guys; guys = ['barry', 'larry', 'harry']; console.log(guys[0]); elements = { hydrogen: 1, silicon: 14, uranium: 92 }; console.log(elements.silicon);
    • Whitespace today = 'tuesday' if today is 'tuesday' console.log 'UXEG' else console.log 'noop'
    • Whitespace var today; today = 'tuesday'; if (today === 'tuesday') { console.log('UXEG'); } else { console.log('noop'); }
    • 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]
    • 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); }
    • Existential operator person = name: 'John Doe' age: 28 console.logperson.name.length console.logperson.non?.existent.property console.logperson.name.reverse?()
    • 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);
    • Classes class Message show: -> console.log 'Foo' class BarMessage extends Message show: -> console.log 'Bar’ new BarMessage().show()
    • Conditionals if a console.log "a is true" else console.log "a is false” console.log "a is false" unless a
    • Scope a = 'A' myFunc = -> a = 'AAA' b = 'B'
    • Scope (function() { var a, myFunc; a = 'A’; myFunc = function() { varb; a = 'AAA'; return b = 'B'; }; }).call(this);
    • String Interpolation name = "John Doe" console.log "Hello #{name}" console.log 'Hello #{name}'
    • String Interpolation var name; name = "John Doe"; console.log("Hello " + name); console.log('Hello #{name}');
    • 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