Created
August 28, 2010 13:47
-
-
Save stephank/555142 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{puts} = require 'sys' | |
MyClass = prototype ~> | |
@doSomething = -> 3 + 5 | |
foobar = new MyClass() | |
puts foobar.doSomething() | |
AnotherClass = prototype inherits MyClass ~> | |
constructor = -> @abc = 3 | |
constructor withInitialValue = (@abc) -> | |
@timesFour: -> @abc * 4 | |
foobar = new AnotherClass() | |
puts foobar.doSomething() | |
puts foobar.timesFour() | |
foobar = new AnotherClass.withInitialValue(8) | |
puts foobar.timesFour() |
This file contains hidden or 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 _a, puts, MyClass, AnotherClass, foobar; | |
_a = require('sys'); | |
puts = _a.puts; | |
MyClass = (function() { | |
var ctor, _b, _c; | |
ctor = function() { | |
this.doSomething = function() { | |
return 3 + 5; | |
}; | |
}; | |
_b = new ctor(); | |
_c = function() {}; | |
_c.prototype = _b; | |
return _c; | |
})(); | |
foobar = new MyClass(); | |
puts(foobar.doSomething()); | |
AnotherClass = (function() { | |
var ctor, _b, _c; | |
ctor = function() { | |
this.timesFour = function() { | |
return this.abc * 4; | |
}; | |
}; | |
ctor.prototype = MyClass.prototype; | |
_b = new ctor(); | |
_c = function() { | |
this.abc = 3 | |
}; | |
_c.prototype = _b; | |
_c.withInitialValue = function(value) { | |
this.abc = value; | |
}; | |
_c.withInitialValue.prototype = _b; | |
return _c; | |
})(); | |
foobar = new AnotherClass(); | |
puts(foobar.doSomething()); | |
puts(foobar.timesFour()); | |
foobar = new AnotherClass.withInitialValue(8); | |
puts(foobar.timesFour()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment