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

推荐订阅源

IT之家
IT之家
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Latest news
Latest news
Scott Helme
Scott Helme
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
LINUX DO - 最新话题
O
OpenAI News
W
WeLiveSecurity
TaoSecurity Blog
TaoSecurity Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
H
Hacker News: Front Page
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
L
LINUX DO - 热门话题
G
GRAHAM CLULEY
I
Intezer
Webroot Blog
Webroot Blog
Cloudbric
Cloudbric
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
C
CERT Recently Published Vulnerability Notes
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Help Net Security
Help Net Security
N
News | PayPal Newsroom
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Last Watchdog
The Last Watchdog
A
Arctic Wolf
The Hacker News
The Hacker News
Apple Machine Learning Research
Apple Machine Learning Research
Project Zero
Project Zero
宝玉的分享
宝玉的分享
B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - DingJun

Javascript 继承方法3 Javascript 继承方法2 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 继承方法1
DingJun · 2007-09-14 · via 博客园 - DingJun

几天学习后总结一下Javascript关于继承的几种方法,基本都是关于原型法的,先看最简单的。

定义基类Person:

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


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

定义子类Employee:

function Employee(first, last, id)
{
   
this.id = id;
}


Employee.prototype
= new Person();
Employee.prototype.constructor
= Employee;

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

通过改变Employee.prototype的原型让Employee继承于Person类:Employee.prototype = new Person();

再定义子类Manager:

function Manager(first, last, id, department) {
   
this.department = department;
}


Manager.prototype
= new Employee();
Manager.prototype.constructor
= Manager;

Manager.prototype.toString
= function()
{
    return this.first + " " + this.last + ": " + this.id
 + ": " + this.department;
}
;

用同样的方法让Manager类继承于Employee类。
缺点:
1,不能调用基类的构造函数以便初始化。
2,不能调用被覆盖的基类中的同名方法。