having fun with code

JS.Class: a very nice object oriented approach

I have been using jQuery and Mootools in the last few months at work, among other libraries. So far, jQuery was my favorite because it is very fast and encapsulated (it doesn’t interfere with other librearies, etc). But I love Mootools too because of its object oriented approach and beautiful things like the Class class which lets you create JS classes very easily. Every time I use jQuery I miss that from Mootools.

Well, a copuple of days ago I have discovered JS.Class which I think is the best thing I have seen so far in object oriented Javascript. It is awesome! Very well designed and documented and very well encapsulated.

JS.Class is not a library for DOM manipulation but just a framework to build object oriented code. And I love that! I think it is way better to focus on a single task, instead of trying to cover it all. This makes JS.Class a very lightweight library too :)

Copy-constructor test class in Mootools:

var myClass = new Class({
  1.   text: '',
  2.   say: function() {
  3.     console.log(this.text);
  4.   }
  5. });

Copy-constructor test class in JS.Class:

var myClass = new JS.Class({
  1.   text: '',
  2.   say: function() {
  3.     console.log(this.text);
  4.   }
  5. });

As you can see, the way of creating classes is almost the same. So what makes JS.Class better than Mootools? Where, both allow inheritance and extending classes with other class-helpers, but JS.Class does this better. I’ll work on some example code to prove this :)

PS: Don’t take me wrong, I still love Mootools and I’ll still use it on web development. But I try to use JS.Class as much as possible.

Related Posts:

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Additional comments powered by BackType

About the blog

This is a blog about development, focused mainly on Javascript but also other languages like python, shell scripts and more.

About the author

Eneko Alonso is a software engineer and UI developer with more than eight years of experience in software and web development. He lives in San Luis Obispo, California and works at LEVEL Studios.

Contact Info

Contact Info