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

推荐订阅源

S
Secure Thoughts
P
Privacy International News Feed
T
Tenable Blog
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
Security Latest
Security Latest
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
I
InfoQ
Spread Privacy
Spread Privacy
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园_首页
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
Latest news
Latest news

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