CoffeeScript - en introduksjon

  • 606 views
Uploaded on

En introduksjon til CoffeeScript.

En introduksjon til CoffeeScript.

  • 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
606
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. Det er bare JavaSript
  • 2. Kompilert
  • 3. Kompilert hello.coffee: alert “hei”
  • 4. Live kompilering<script type="text/javascript" src="coffeescript.js"></script><script type="text/javascript" src="hello.coffee"></script>
  • 5. Live kompilering<script type="text/javascript" src="coffeescript.js"></script><script type="text/coffeescript"> alert “hei”</script>
  • 6. $ coffee -c hello.coffee$ lshello.coffee hello.js
  • 7. Indentgrade: (student) -> if student.excellent_work “A+” else if student.okay_stuff if student.tried_hard then “B” else “B-” else “C”
  • 8. var grade = function(student) { if (student.excellent_work) { return “A + ”; } else if (student.okay_stuff) { if (student.tried_hard) { return “B”; } else { return “B - ”; } } else { return “C”; }};
  • 9. Funksjonersquare = (x) -> x * xcube = (x) -> square(x) * xvar cube, square;square = function(x) { return x * x;};cube = function(x) { return square(x) * x;};
  • 10. Verdisetting
  • 11. yearsOld = max: 10, ida: 9, tim: 11ages = for child, age of yearsOld "#{child} is #{age}"var age, ages, child, yearsOld;yearsOld = { max: 10, ida: 9, tim: 11};ages = (function() { var _results; _results = []; for (child in yearsOld) { age = yearsOld[child]; _results.push("" + child + " is " + age); } return _results;})();
  • 12. Operators/aliaser
  • 13. CoffeeScript JavaScript is === isnt !== not ! and && or !!true, yes, on truefalse, no, off false @, this this of in in finnes ikke
  • 14. launch() if ignition is onif (ignition === true) launch();volume = 10 if band isnt SpinalTapif (band !== SpinalTap) volume = 10;letTheWildRumpusBegin() unless answer is noif (answer !== false) letTheWildRumpusBegin();
  • 15. if car.speed < limit then accelerate()if (car.speed < limit) accelerate();winner = yes if pick in [47, 92, 13]if (pick === 47 || pick === 92 || pick === 13)winner = true;print "My name is #{@name}"print("My name is " + this.name);
  • 16. The existential operatorif hungry? eat()if (typeof hungry !== “undefined” && hungry !== null) { eat();}
  • 17. launch() if ignition is onif (ignition === true) launch();volume = 10 if band isnt SpinalTapif (band !== SpinalTap) volume = 10;letTheWildRumpusBegin() unless answer is noif (answer !== false) letTheWildRumpusBegin();
  • 18. Klasser
  • 19. class Animal constructor: (@name) -> move: (meters) -> alert @name + " moved #{meters}m."class Snake extends Animal move: -> alert "Slithering..." super 5
  • 20. var Animal, Snake;var __hasProp =Object.prototype.hasOwnProperty, __extends =function(child, parent) { for (var key in parent) { if(__hasProp.call(parent, key)) child[key] =parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child;};Animal = (function() { function Animal(name) { this.name = name;
  • 21. coffeescript.com