# JS.Class 2.0

**URL:** <https://www.ruby-forum.com/t/js-class-2-0/146314>\
**Category:** Ruby\
**Created:** [August 19, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/js-class-2-0/146314 "2008-08-19T23:47:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 19, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/js-class-2-0/146314/1 "2008-08-19T23:47:44Z")

</div>

Hello list,  
Do please forgive me if this is a little too off-topic but I thought  
some  
folks here might be interested. I recently released version 2.0 of  
JS.Class,  
my JavaScript library that implements some of Ruby’s OOP features in  
JavaScript. It is not a Ruby interpreter; rather it brings various  
idioms  
found in Ruby OO programs to JavaScript, allowing for classes, modules,  
inheritance, metaprogramming hooks, and ports of a few classes in the  
Ruby  
stdlib amongst other things.

If there’s anybody here who’s into JavaScript I would be thrilled if  
they  
would give it a try and let me know about any weak spots where it might  
deviate from Ruby-like behaviour. This release is the closest to Ruby  
I’ve  
managed to get so far, and I’d love some help from the Ruby community to  
iron out any obscure use cases.

Anyway, without further ado:  
[http://jsclass.jcoglan.com/](http://jsclass.jcoglan.com/)

Any help/feedback very welcome indeed.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 20, 2008, 12:08am UTC](https://www.ruby-forum.com/t/js-class-2-0/146314/2 "2008-08-20T00:08:13Z")

</div>

James C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> If there’s anybody here who’s into JavaScript I would be thrilled if they  
> would give it a try and let me know about any weak spots where it might  
> deviate from Ruby-like behaviour. This release is the closest to Ruby I’ve  
> managed to get so far, and I’d love some help from the Ruby community to  
> iron out any obscure use cases.
> 
> Anyway, without further ado:  
> [http://jsclass.jcoglan.com/](http://jsclass.jcoglan.com/)
> 
> Any help/feedback very welcome indeed.

Ok, well, first impressions:

- It seems fairly large for what it appears to do. But I’ve not  
investigated this in depth.

- There’s no in-line documentation, which is a pain if you’re  
evaluating code.

- I’m quite certain using constructors as the basis for classes is  
just wrong in javascript. I don’t have the time now to go into this  
in depth. I put some earlier explanations about constructors online  
here:

[http://joost.zeekat.nl/constructors-considered-mildly-confusing.html](http://joost.zeekat.nl/constructors-considered-mildly-confusing.html)

At the moment I think that any code that’s serious about building  
classes in JS should start from something similar to Crockford’s  
“begetObject”:

[http://javascript.crockford.com/prototypal.html](http://javascript.crockford.com/prototypal.html)

and forget about constructors all together.

- I’m not certain that you should even try not to “deviate from  
Ruby-like behaviour”. You’re not writing a ruby library, after all.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 20, 2008, 10:33am UTC](https://www.ruby-forum.com/t/js-class-2-0/146314/3 "2008-08-20T10:33:25Z")

</div>

James C. wrote:

> would give it a try and let me know about any weak spots where it might  
> deviate from Ruby-like behaviour. This release is the closest to Ruby I’ve  
> managed to get so far, and I’d love some help from the Ruby community to  
> iron out any obscure use cases.
> 
> Anyway, without further ado:  
> [http://jsclass.jcoglan.com/](http://jsclass.jcoglan.com/)
> 
> Any help/feedback very welcome indeed.

That looks pretty complete and well documented.

I am mostly interested in how you implemented Ruby’s meta model  
(classes, modules and meta-classes), as that’s the hardest part  
at all. Mainly the circular dependency between Class and Object  
(a Class in Ruby inherits from Object, and Object is an instance  
of Class and as such an instance of itself :).

Note that I wrote RubyJS [1](http://www.ntecs.de/projects/rubyjs) which is a Ruby to Javascript compiler.  
It supports all Ruby constructs (including method\_missing) with the  
only limitation being that classes and methods are fixed at compile  
time, but you can use meta-programming in the pre-compilation stage  
(most of the time you will not notice the difference!).

Regards,

Michael
