问题
I've found http://ejohn.org/blog/simple-javascript-inheritance/ and it's exactly what I'm searching for but 'm wondering if it still works and if can cause any issue.
回答1:
Many modern libraries use classical inheritance now. Its core method is the following (JavaScript Patterns by Stoyan Stefanov, page 127):
function inherit(C, P) {
var F = function () {};
F.prototype = P.prototype;
C.prototype = new F();
C.uber = P.prototype;
C.prototype.constructor = C;
}
Example of projects where it's used are:
- Google Closure
- YUI
- ExtJS
来源:https://stackoverflow.com/questions/11072386/is-simple-javascript-inheritance-by-john-resig-still-ok