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

推荐订阅源

N
News and Events Feed by Topic
WordPress大学
WordPress大学
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
L
LangChain Blog
雷峰网
雷峰网
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
NISL@THU
NISL@THU
Scott Helme
Scott Helme
量子位
S
Security Affairs
T
Threat Research - Cisco Blogs
博客园_首页
云风的 BLOG
云风的 BLOG
D
Docker
AWS News Blog
AWS News Blog
腾讯CDC
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
U
Unit 42
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Last Watchdog
The Last Watchdog
C
Cybersecurity and Infrastructure Security Agency CISA
IT之家
IT之家
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
S
Security @ Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
I
InfoQ

博客园 - 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不会将它覆盖。