Created
September 11, 2012 21:16
-
-
Save verma/3702124 to your computer and use it in GitHub Desktop.
Testing class inheritance in Coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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