Skip to content

Instantly share code, notes, and snippets.

@verma
Created September 11, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verma/3702124 to your computer and use it in GitHub Desktop.
Save verma/3702124 to your computer and use it in GitHub Desktop.
Testing class inheritance in Coffeescript
var Bye, Greeting, Hello,
__hasProp = {}.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; };
Greeting = (function() {
function Greeting() {}
Greeting.prototype.initialize = function() {
return this.message = "Hello";
};
Greeting.prototype.hello = function(name) {
return alert("" + this.message + " " + name);
};
return Greeting;
})();
Hello = (function(_super) {
__extends(Hello, _super);
function Hello() {
return Hello.__super__.constructor.apply(this, arguments);
}
Hello.prototype.hello = function() {
return Hello.__super__.hello.call(this, 'James Bond');
};
return Hello;
})(Greeting);
Bye = Greeting.extend({
hello: function() {
return hello.__super__.constructor.call(this, 'Bames Jond');
}
});
class Greeting
initialize: ->
@message = "Hello"
hello: (name) ->
alert "#{@message} #{name}"
class Hello extends Greeting
hello: ->
super('James Bond')
Bye = Greeting.extend
hello: ->
super('Bames Jond')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment