1 / 10

CoffeeScript

CoffeeScript. Katie Soto Casey Foster. Origin. 2009 , Jeremy Ashkenas made the first Git commit of CoffeeScript Compiler originally written in Ruby ; pure CoffeeScript Compiler in 2010. 2010 stable release Jeremy Ashkenas .. worked for DocumentCloud

isleen
Télécharger la présentation

CoffeeScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CoffeeScript Katie Soto Casey Foster

  2. Origin • 2009, Jeremy Ashkenas made the first Git commit of CoffeeScript • Compileroriginally written in Ruby; pure CoffeeScript Compiler in 2010. • 2010 stable release • Jeremy Ashkenas.. • worked for DocumentCloud • produced several open source projects • backbone.js • underscore.js. • two-time winner of the Apps for America contest • Know Thy Congressman • Quakespotter • created Ruby-Processing

  3. About • Compiles into JavaScript • Is an attempt to expose the good parts of JavaScript in a simple way. • The golden rule: "It's just JavaScript" • Code compiles one-to-one into the equivalent JS • No interpretation at runtime • Can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa).

  4. Example • CoffeeScript allows you to: • Imply curly braces with indentation • Use natural words like "and, then, else or" • Leave off semi-colons • It's like if Ruby and Python had a lovechild

  5. More examples JavaScript Multiply each item in a list by 2 vari, num, nums;nums= [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];for (iinnums) { num =nums[i];nums[i] = num * 2;} Sum a list of numbers var n, sum;sum = 0;for (n = 1; n <= 100; n++) { sum += n;} CoffeeScript Multiply each item in a list by 2 nums= [1..10] fori, num ofnums nums[i] = num*2 Sum a list of numbers sum = 0 for n in [1..100] sum += n

  6. Classes CoffeeScript class Animal constructor: (@name) -> who: -> alert @name goat = new Animal 'Billy' goat.who() JavaScript var Animal, goat;Animal = (function() { function Animal(name) { this.name = name; }Animal.prototype.who = function() { return alert(this.name); }; return Animal;})();goat = new Animal('Billy');goat.who();

  7. Inheritance CoffeeScript class Goat extends Animal who: -> alert "I am #{@name} the Goat!" JavaScript varGoat, __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; }; Goat = (function(_super) { __extends(Goat, _super); function Goat() {Goat.__super__.constructor.apply(this, arguments); } Goat.prototype.who = function() { return alert("I am " + this.name + " the Goat!"); }; return Goat; })(Animal);

  8. Summary • CoffeeScript is awesome • It accentuates the best parts of JavaScript • It is Ruby and Python's lovechild, stealing every shortcut it can from them • It makes classes and inheritance tolerable to read • And underneath it all... It's just JavaScript!

  9. Equivalent JavaScript Demo CoffeeScript

  10. Demo

More Related