最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Improvement over John Resig's JavaScript class framework - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jun 20, 2011 at 23:22 Alex TurpinAlex Turpin 47.8k23 gold badges116 silver badges146 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

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.");
    }
});

You may check out this extended version of John Resig's Class model:

https://github.com/riga/jclass

It's still build on prototypes but also provides private members using closures.

发布评论

评论列表(0)

  1. 暂无评论