Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improvement over John Resig's JavaScript class framework

Good day all,

I've recently been looking around for a nice simple JavaScript class framework which only does basic inheritance. I found John Resig's example framework on his blog and I find it to be quite satisfactory for my needs. However, the post dates from 2008, and this is, after all, the web we're talking about.

So my question is, would you guys use that system as is, or would there be improvements to make, things that have been discovered over the years? Or perhaps an existing, actively supported class framework that resembles this one?

Thanks.

like image 786
Alex Turpin Avatar asked Jun 20 '11 23:06

Alex Turpin


2 Answers

You might want to take some advice from Douglas Crockford (my emphasis):

I have been writing JavaScript for 8 years now, and I have never once found need to use an uber function. ... I now see my early attempts to support the classical model in JavaScript as a mistake.

Douglas Crockford, Classical Inheritance in JavaScript,

like image 156
RobG Avatar answered Sep 20 '22 08:09

RobG


The guys of JavaScriptMVC did a great job of creating a Class implementation based on John Resigs framework example:

Class provides simulated inheritance in JavaScript. Use clss to bridge the gap between jQuery's functional programming style and Object Oriented Programming. It is based off John Resig's Simple Class Inheritance library. Besides prototypal inheritance, it includes a few important features:

Static inheritance
Introspection
Namespaces
Setup and initialization methods
Easy callback function creation

All other parts of the framework are based on Class but you can also use it standalone (less than 6Kb compressed). I especially like the callback functions and the static inheritance. Use it like this:

$.Class.extend('My.Class',
{
    // Static properties
},
{
    init : function(args)
    {
            // This is the constructor
    },

    classMethod : function()
    {
        alert("Class method called.");
    }
});
like image 24
Daff Avatar answered Sep 21 '22 08:09

Daff