Created
January 12, 2011 12:41
-
-
Save bartschuller/776112 to your computer and use it in GitHub Desktop.
Figuring out prototypes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var A, B, a, b, print, sys; | |
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { | |
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } | |
function ctor() { this.constructor = child; } | |
ctor.prototype = parent.prototype; | |
child.prototype = new ctor; | |
child.__super__ = parent.prototype; | |
return child; | |
}; | |
sys = require('sys'); | |
print = sys.print; | |
A = (function() { | |
function A() {} | |
A.prototype.bar = function() { | |
print("A's bar\n"); | |
return this.baz(); | |
}; | |
A.prototype.baz = function() { | |
return print("A's baz\n"); | |
}; | |
return A; | |
})(); | |
B = (function() { | |
function B() { | |
B.__super__.constructor.apply(this, arguments); | |
} | |
__extends(B, A); | |
B.prototype.baz = function() { | |
return print("B's baz\n"); | |
}; | |
return B; | |
})(); | |
a = new A; | |
a.bar(); | |
b = new B; | |
b.bar(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment