Which JavaScript library has the most comprehensive support for class inheritance?

After playing with a dozen different JavaScript libraries such as Prototype, jQuery, YUI, just to name a few, I found that every other library has a different way of modeling some kind of class hierarchy and provides some support for the inheritance class. (Except jQuery) Also, what is very annoying is that when you create a new class, it should be library dependent, unless you follow the simple old way.

I am wondering which library offers the best support for class inheritance in general and why.

I hope that once the authors of the JavaScript library can agree on one style of creating and inheriting classes.

+19
javascript javascript-framework
Apr 02 '09 at 19:23
source share
9 answers

I think Microsoft Ajax implements it just fine (with namespaces, inheritance and interfaces, etc.)

Example:

Type.registerNamespace("Demo"); Demo.Person = function(firstName, lastName, emailAddress) { this._firstName = firstName; this._lastName = lastName; this._emailAddress = emailAddress; } Demo.Person.prototype = { getFirstName: function() { return this._firstName; }, getLastName: function() { return this._lastName; }, getName: function() { return this._firstName + ' ' + this._lastName; }, dispose: function() { alert('bye ' + this.getName()); } } Demo.Person.registerClass('Demo.Person', null, Sys.IDisposable); // Notify ScriptManager that this is the end of the script. if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
+7
Apr 02 '09 at 19:24
source share

I found out that there is a Javascript Framework modeled after Ruby:

Js.class

Another good one is:

Joose-js (modeled after moose (perl))

I prefer Josse because it seems to be more actively developing, and the syntax also looks neat!

Any thoughts ??? (Maybe this should be another question?)

+7
Apr 03 '09 at 15:51
source share

You should try Classy:

http://classy.pocoo.org/

It is simple and very small, but there is everything that I need when building my classes.

+7
Jul 27 '10 at 19:15
source share

Check out the Prototype . Here's a sample:

 // properties are directly passed to `create` method var Person = Class.create({ initialize: function(name) { this.name = name; }, say: function(message) { return this.name + ': ' + message; } }); // when subclassing, specify the class you want to inherit from var Pirate = Class.create(Person, { // redefine the speak method say: function($super, message) { return $super(message) + ', yarr!'; } }); var john = new Pirate('Long John'); john.say('ahoy matey'); // -> "Long John: ahoy matey, yarr!" 
+5
Apr 02 '09 at 19:35
source share

Base2 has a simple inheritance mechanism, see John Resig post about this (comments in the post are also interesting).

Something to keep in mind is that trying to model the syntax of classic OO in Javascript has been breaking a lot lately (although it was very enthusiastically studied in the early days of the great revolution of the JS library).

+5
Apr 2 '09 at 19:55
source share

You may also be interested in qooxdoo, a platform for building rich Internet applications (RIAs). It includes a comprehensive OO layer that aims to be powerful, elegant and fast:

See the following section of the manual for all the details: http://qooxdoo.org/documentation/0.8#object_orientation

+2
Jul 20 '09 at 14:35
source share

I find mootools to be everything I need to inherit. It uses the main motive of the extensions and tools of many other OO languages.

One of the developers considers it in detail in comparison with jquery:

http://jqueryvsmootools.com

You also do not need the whole library. You can simply load your class model and ignore the rest (animation, house manipulation, etc.).

+1
Jul 20 '09 at 14:39
source share

Just choose the one you like. After all, they all use prototype inheritance behind the scenes, so they all have roughly the same level of functionality.

If you want a powerful traditional class system, use GWT and the program in pure Java.

Personally, I prefer the Ext component system, but because Ext components actually have a full life cycle (initialization, rendering, state preservation and destruction), which, in turn, allows component plugins that do not break with minor updates in the library.

+1
Jul 27 '10 at 21:15
source share

Well, first you have to ask if you want a library that is trying to imitate classical inheritance or one that is more suitable for JS's own prototype inheritance.

DUI (Digg User Interface Library) is a jQuery addon that uses the old Prototype model and extends it in a more intuitive way, allowing nested static and dynamic classes, namespaces, support for dontEnum bits, etc. Documentation is available on Digg GitHub . I think you will find it pretty reliable.

Disclosure: I work for Digg and wrote DUI;)

0
Apr 03 '09 at 0:04
source share



All Articles