If you look at this rationally, it's actually pretty sane. It's just very simple JavaScript OOP inline with translated code. Even more beautiful is the output of modules:
module Run
def run
puts "I am running!"
end
end
module Jump
def jump
puts "I am jumping!"
end
end
class Foo
include Run
include Jump
end
mario = Foo.new
mario.run
mario.jump
translates to:
(function() {
var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice, __module = __opal.module, __klass = __opal.klass;
// Define Mario
var mario = nil;
// Javascript "Run" class
(function(__base){
// line 2, (file), module Run
function Run() {};
Run = __module(__base, "Run", Run);
var Run_prototype = Run.prototype, __scope = Run._scope;
Run_prototype.$run = function() {
return this.$puts("I am running!");
}
;Run._donate(["$run"]);
})(self);
// Javascript "Jump" class
(function(__base){
// line 8, (file), module Jump
function Jump() {};
Jump = __module(__base, "Jump", Jump);
var Jump_prototype = Jump.prototype, __scope = Jump._scope;
Jump_prototype.$jump = function() {
return this.$puts("I am jumping!");
}
;Jump._donate(["$jump"]);
})(self);
// JavaScript "Foo" class
(function(__base, __super){
// line 14, (file), class Foo
function Foo() {};
Foo = __klass(__base, __super, "Foo", Foo);
var Foo_prototype = Foo.prototype, __scope = Foo._scope;
// $include Run / Jump
Foo.$include(__scope.Run);
return Foo.$include(__scope.Jump);
})(self, null);
// The ruby executing code translation
mario = __scope.Foo.$new();
mario.$run();
return mario.$jump();
})();
While we are posting contrived examples. What was ever wrong with this?
var Foo = function() {};
Foo.prototype.jump = function() {
return "I jump."
};
Foo.prototype.run = function() {
return "I run."
};
var mario = new Foo();
mario.run();
mario.jump();
I can't imagine that opal code running nearly as fast as javascript. And if we are waving around compiled js - coffeescript does a much better job of being readable. You just black-boxed the whole thing. I like to know what is happening with my js.
Cool for the rubyist in you i guess. I just kinda go o_0