是“简单Javascript继承";约翰·雷西格(John Resig)还行吗 [英] is "Simple Javascript Inheritance" by John Resig still ok?

查看:138
本文介绍了是“简单Javascript继承";约翰·雷西格(John Resig)还行吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 http://ejohn.org/blog/simple-javascript-inheritance /,这正是我要搜索的内容,但我想知道它是否仍然有效以及是否会引起任何问题.

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.

推荐答案

许多现代图书馆现在都在使用经典继承.其核心方法如下(Stoyan Stefanov撰写的JavaScript Patterns,第127页):

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; 
} 

使用它的项目示例是:

  • Google Closure
  • YUI
  • ExtJS

这篇关于是“简单Javascript继承";约翰·雷西格(John Resig)还行吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆