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