PageRenderTime 30ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/js/classes.js

http://github.com/jashkenas/coffee-script
JavaScript | 57 lines | 38 code | 18 blank | 1 comment | 2 complexity | 3ddf901f607c4d71382fad058e948a3a MD5 | raw file
 1// Generated by CoffeeScript 1.10.0
 2var Animal, Horse, Snake, sam, tom,
 3  extend = 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; },
 4  hasProp = {}.hasOwnProperty;
 5
 6Animal = (function() {
 7  function Animal(name) {
 8    this.name = name;
 9  }
10
11  Animal.prototype.move = function(meters) {
12    return alert(this.name + (" moved " + meters + "m."));
13  };
14
15  return Animal;
16
17})();
18
19Snake = (function(superClass) {
20  extend(Snake, superClass);
21
22  function Snake() {
23    return Snake.__super__.constructor.apply(this, arguments);
24  }
25
26  Snake.prototype.move = function() {
27    alert("Slithering...");
28    return Snake.__super__.move.call(this, 5);
29  };
30
31  return Snake;
32
33})(Animal);
34
35Horse = (function(superClass) {
36  extend(Horse, superClass);
37
38  function Horse() {
39    return Horse.__super__.constructor.apply(this, arguments);
40  }
41
42  Horse.prototype.move = function() {
43    alert("Galloping...");
44    return Horse.__super__.move.call(this, 45);
45  };
46
47  return Horse;
48
49})(Animal);
50
51sam = new Snake("Sammy the Python");
52
53tom = new Horse("Tommy the Palomino");
54
55sam.move();
56
57tom.move();