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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Allen Zhang

oracle数据库的字符集更改 用SQL server导出到oracle,查询时提示“表或视图不存在ORA-00942”错误 由于无法创建应用程序域,因此未能执行请求。错误: 0x80070002 系统找不到指定的文件 导出Excel时发生COM组件失败的解决方案 jquery下一个空格带来的血案 Web应用系统中关闭Excel进程 C++数据类型与C#对应关系 c#调用WINDWOS API时,非常有用(转) 水晶报表的交叉表中增加超级链接 SQL SERVER 2000数据库置疑处理 ScriptX控件部分参数说明 - Allen Zhang - 博客园 给ASP.net程序配置代理服务器 使用jQuery的validation后,无法引发asp.net按钮的事件处理程序 使用代码模拟请求和提交网页数据 - Allen Zhang - 博客园 C#调用Delphi写的动态链接库 - Allen Zhang - 博客园 近期一些超值文章及工具收集 用STSADM工具全自动备份sharepoint站点 创建MOSS网站下的新闻 SQL Server Reporting Services与MOSS集成资料汇总 修复MOSS2007备份还原后搜索服务出现的问题(续) - Allen Zhang - 博客园
JavaScript和ExtJS的继承 Ext.extend Ext.applyIf (转)
Allen Zhang · 2009-10-25 · via 博客园 - Allen Zhang

首先看一下经典的JavaScript的继承机制。

定义一个名为BaseClass的类,然后为BaseClass定义两个函数:someMethod()和overridenMethod().

var BaseClass = function(){
//do something
};
BaseClass.prototype.someMethod 
= function(){
//do something
};
BaseClass.prototype.overridenMethod 
= function(){
//do something
};

使用传统方式在JavaScript中实现类的继承操作

var SubClass = function(){
   BaseClass.call(
this);
};
SubClass.prototype 
= new BaseClass();
SubClass.prototype .newMethod 
= function(){
  
//do something
};
SubClass.prototype.overridenMethod 
= function(){
  
//do something
};

SubClass的构造函数中首先调用BaseClass的构造函数初始化数据,然后通过

SubClass.prototype = new BaseClass();

这条语句让SubClass类获得BaseClass中的所有属性和函数,从而实现了JavaScript中的继承操作,为子类添加了新函数而且覆盖了父类中的同名函数。

在ExtJS中使用Ext.extend()函数实现继承功能

var SubClass = function(){
    SubClass.superclass.constructor.call(
this);
};
Ext.extend(SubClass,BaseClass,{
    newMethod: 
function(){};
    overridenMethod: 
function(){};
};

Ext.extend()函数提供了直接访问父类构造函数的途径,通过SubClass.superclass.constructor.call(this);就可以直接调用父类的构造函数,这个函数的第一个参数总是this,以确保父类的构造函数在子类的作用域里工作。
如果父类的构造函数需要传入参数,可以讲所需的参数直接传递给它:
SubClass.superclass.constructor.call(this,config);这样就得到了一个继承了父类的所有属性和函数的子类。

Ext.apply函数的作用是将一个对象中的所有属性都复制到另一个对象中。
Ext.applyIf与Ext.apply的作用类似,区别在于如果某个属性在目标对象中已经存在,则Ext.applyIf不会将它覆盖。