Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我找到了http://ejohn.org/blog/simple-javascript-inheritance/这正是我正在寻找的东西,但我想知道它是否仍然有效以及是否会导致任何问题。
现在许多现代库都使用经典继承。它的核心方法如下(Stoyan Stefanov 的 JavaScript 模式,第 127 页):
function inherit(C, P) { var F = function () {}; F.prototype = P.prototype; C.prototype = new F(); C.uber = P.prototype; C.prototype.constructor = C; }
使用它的项目示例如下: