Skip to content

Instantly share code, notes, and snippets.

@stephank
Created August 28, 2010 13:47
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 stephank/555142 to your computer and use it in GitHub Desktop.
Save stephank/555142 to your computer and use it in GitHub Desktop.
{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()
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