Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A standalone version of prototype's Class interface
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


It's Class.create() from prototype, but standalone. Yep, that's it.

Version 1.7 from

View the docs at (the new way)

Unminified: 9.11k
Minified: 2.06k
Minified+gzip: <1.7k

What's not to love?

PTClass JS Inheritance Findings

"When a member is sought and it isn't found in the object itself, then it is taken from the object's constructor's prototype member."
--Douglas Crockford

      // Classes
      var A = Class.create( {
        id: "A",
        initialize: function () {
 = function () {
            return "A - PRIVILEGED, from " +;
        foo: function () {
          return "A - PROTO, from " +;
      } );
      var B = Class.create( A, {
        id: "B",
        initialize: function($super){
        foo: function ($super) {
          return $super() + " :: B - PROTO, from " +;
      var a = new A();
      var b = new B();

1. For and, instance calls the privileged method

2. If B inherits from A and we create method, calling instance calls _the privileged method A.foo_. Since B inherits from A which has the privileged method foo, that gets called before the prototype is searched.

3. Now if we create an empty initialize method on B, this seems to break the privileged inheritance chain, since calling really calls Furthermore, $super within references, not A's privileged method. $super seems to always reference the prototype method.

4. Next, adding $super() within B's initialize method, restores the inheritance chain as in case #2 above.

5. When called from, The this keyword points to the instance b even from within the privileged method at "this" always refers to the instance.

6. Adding a privileged method onto B overrides the same method on A – trumps – but using $super to call the parent method won't work.

7. Calling $super() from within B.initialize after declaring there will override with Conversely, declaring after calling $super() will override

8. Privileged methods may only consist of private attribute getters, which can then be used by public methods, which in turn can easily be extended.
Something went wrong with that request. Please try again.