Skip to content

Commit

Permalink
Expose SubClass.base as a synonym for BaseClass.prototype.
Browse files Browse the repository at this point in the history
Closes #2.
  • Loading branch information
benjamn committed Jun 15, 2013
1 parent 305fd20 commit be8299c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function makeClass(base, newProps) {
// extend between all classes.
constructor.prototype = ownProto;
constructor.extend = extend;
constructor.base = baseProto;

// Setting constructor.prototype.constructor = constructor is
// important so that instanceof works properly in all browsers.
Expand Down
29 changes: 29 additions & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,32 @@ exports.testStatics = function(t, assert) {

t.finish();
};

exports.testBaseProperty = function(t, assert) {
var A = Class.extend({
foo: function() {
return "name: " + this.name;
}
});

var B = A.extend({
name: "B",

bar: function() {
assert.strictEqual(B.base.bar, this._super);
return B.base.foo.call(this);
}
});

var C = B.extend({
name: "C"
});

assert.strictEqual(B.base, A.prototype);
assert.strictEqual(C.base, B.prototype);

assert.strictEqual(new B().bar(), "name: B");
assert.strictEqual(new C().bar(), "name: C");

t.finish();
};

0 comments on commit be8299c

Please sign in to comment.