4 ms·
Yup, that's some good brainfuck: (function() { var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.break
by 1qaz2wsx3edc 14y ago
Yup, that's some good brainfuck:
(function() {
var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice, __klass = __opal.klass;
var adam = nil, __a, __b;
(__b = [1, 2, 3, 4], __b.$each._p = (__a = function(a) {
if (a == null) a = nil;
return this.$puts(a)
}, __a._s = self, __a), __b.$each());
(function(__base, __super){
// line 5, (file), class Foo
function Foo() {};
Foo = __klass(__base, __super, "Foo", Foo);
var Foo_prototype = Foo.prototype, __scope = Foo._scope;
return Foo_prototype.$name = function() {
if (this.name == null) this.name = nil;
return this.name
},
Foo_prototype['$name='] = function(val) {
return this.name = val
}, nil
})(self, null);
adam = __scope.Foo.$new();
adam['$name=']("Adam Beynon");
return self.$puts(adam.$name());
})();
- ghayes 14y agoIf 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(); })();
- sic1 14y agoWhile 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