is “Simple Javascript Inheritance” by John Resig still ok?

ぐ巨炮叔叔 提交于 2019-12-07 08:48:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!