惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园_首页
D
Docker
S
Security @ Cisco Blogs
K
Kaspersky official blog
爱范儿
爱范儿
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
V
V2EX
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Troy Hunt's Blog
Cloudbric
Cloudbric
博客园 - 三生石上(FineUI控件)
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Hacker News
The Hacker News
美团技术团队
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Martin Fowler
Martin Fowler
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tor Project blog
Vercel News
Vercel News
The Cloudflare Blog
G
Google Developers Blog
T
Threat Research - Cisco Blogs
AI
AI
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
Scott Helme
Scott Helme
S
Schneier on Security
大猫的无限游戏
大猫的无限游戏
The GitHub Blog
The GitHub Blog
S
Securelist
IT之家
IT之家
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - DingJun

Javascript 继承方法2 Javascript 继承方法1 Call web service from excel Cannot load type (加载页面出错) 几个主流的浏览器引擎及判定 防止数据库日志文件增长 配置发布数据库服务器时碰到错误18483 一些有关。NET界面处理与多线程的文章 不可恢复的生成错误 在.Net安装项目中如何判断操作系统的版本 修改dataConfiguration.config文件 SQL Server 使用外部连接 在.NET下利用目录服务操纵本机用户和用户组 System.windows.forms.datagrid控件使用技巧 读取配置文件中的自定义节 区域设置与格式化(1) 默认的 IIS MIME 类型关联 在.NET中使用XPath查找指定元素时遇到的麻烦(以dataConfiguration.config为例) 使用Data access block
Javascript 继承方法3
DingJun · 2007-09-14 · via 博客园 - DingJun
方法3是方法2的小小改进,对子类的定义方式有所改进,更像是C#中类的定义方式,也是Yahoo Library中使用的方法:
// namespace 
JsDev = {};

JsDev.extend = function(subClass, baseClass, overrides) {
   if( ! subClass|| ! baseClass)
   {
         throw new Error("inheritance error");
   }
   function inheritance() {}
   inheritance.prototype = baseClass.prototype;

   subClass.prototype = new inheritance();          // 改变子类的原型,使其原型与父类原型串连起来
   subClass.prototype.constructor = subClass;       // 改变子类的构造函数   与方法2的区别:去掉对基类构造函数的引用
   /*subClass.baseConstructor = baseClass;*/            // 保存对基类构造函数的引用,以便在子类中调用
   subClass.superClass = baseClass.prototype;       // 保存对父原型的引用
   if(overrides)
   {
       for(var i in overrides)
       {
          subc.prototype[i] = overrides[i];
       }
   }
}

//Person class
function Person(first, last) {
    this.first = first;
    this.last = last;
}

Person.prototype.toString = function() {
    return this.first + " " + this.last;
};


//Employee class
function Employee(first, last, id) {    
    //与方法2的区别    
    if(first)      
       Employee.superClass.constructor.call(this, first, last); // 调用父类中的构造函数     
    Employee.baseConstructor.call(this, first, last);  // 调用父类中的构造函数
    this.id = id;
}
// subclass 
JsDev.extend(Employee, Person);
Employee.prototype.toString = function() {
    return Employee.superClass.toString.call(this) + ": " + this.id;  // 调用父类中被覆盖的同名方法
};

//Managerfunction 
Manager(first, last, id, department) {
    //与方法2的区别
    if(first)
       Manager.superClass.constructor.call(this, first, last, id); // 调用父类中的构造函数
    Manager.baseConstructor.call(this, first, last, id);
    this.department = department;
}

// subclass Employee
JsDev.extend(Manager, Employee);
Manager.prototype.toString = function() {
    return Manager.superClass.toString.call(this) + ": " + this.department;
};
子类还可以这样定义:
//Employee class
function Employee(first, last, id) {    
    if(first)      
       Employee.superClass.constructor.call(this, first, last); // 调用父类中的构造函数     
    this.id = id;
}
// subclass 
PersonJsDev.extend(Employee, Person,
    {
        toString : function() 
        {
            return Employee.superClass.toString.call(this) + ": " + this.id;  // 调用父类中被覆盖的同名方法
         },
        anotherMethod: function() 
{
} } )