Changes are in red. The implementations stay the same but the code syntax is different. It's a bit of a hassle if you have little bit of code and, for a lot of code, it's even more of a hassle.

Why can't I reuse my code as-is with only a few modifications? Something like this:function Person(isDancing){

this.dancing = isDancing;

}

Person.prototype.dance = function(){

return this.dancing;

};

Person = Class.extend(Person);

function Ninja(){

this._super( false );

}

Ninja.prototype.dance = function(){

// Call the inherited version of dance()

return this._super();

};

Ninja.prototype.swingSword = function(){

return true;

};Ninja = Person.extend(Ninja);

Instead of rewriting the code into a new code syntax, I only add an extend() call at the end of each new JavaScript class. Once I've done that, if I want, I can call this._super() where ever I need to.

I make this possible using a slight modification to John Resig's script. By checking to see if the argument passed to extend() is a function, instead of an object, the script can handle both syntaxes: John Resig's original syntax and the traditional JavaScript object syntax.

When a function is detected, instead of an object, the function is first saved to the init property. Then, all enumerable function properties (which will behave pretty much like static variables in classical class-based systems) are saved to the function's prototype object. Finally, and here's the magic pixie dust, the function's prototype object is used as the argument which the rest of the code generates the JavaScript class from. John Resig's code behaves the same but the function's prototype object becomes "the class object" instead of being directly passed as the original argument.

Person = Class.extend(Person);

...

Ninja = Person.extend(Ninja);

The extend() calls above take the JavaScript constructor functions and return the new JavaScript class. By assigning the return value to the function (variable), the new JavaScript class replaces the traditional JavaScript object creation function.

With this modification and technique, you can write traditional JavaScript object code and, if you later want to use John Resig's "Simple JavaScript Inheritance", you can add it with ease.