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.
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,
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.");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With