ExtJS superclass.constructor.call(this, config)
来源:互联网 发布:vb中name是什么意思 编辑:程序博客网 时间:2024/06/03 13:25
ExtJS继承Extend 5
MyGridPanel = Ext.extend(Ext.grid.GridPanel, {
constructor: function(config) {
// Your preprocessing here
MyGridPanel.superclass.constructor.apply(this, arguments);
// Your postprocessing here
},
your方法: function() {
// etc.
}
});
以上是Extjs API关于Extend的用法说明,有点不理解,
1.这里的constructor就是一个普通的方法吗,可是在实例化MyGridPanel的时候会自动调用该方法?
2.MyGridPanel.superclass.constructor.apply(this, arguments); 这行代码的作用是什么?有人说是调用父类构造函数,这个父类是指哪个?这里的superclass是什么意思?还有这里的参数arguments可以换成传进来的config吗?
3.在 MyGridPanel.superclass.constructor.apply(this, arguments);这行代码的前后的代码应该做什么?有什么作用?
这部分看了好久 一直没整明白 JS一直半解,还请达人解释解释2013年7月08日 18:31b30164
3
0 0 5- 1条评论
- 关注(0)
1个答案按时间排序按投票排序
- 00
采纳的答案
1. constructor这个方法其实就是最后的 MyGridPanel,也就相当于
MyGridPanel = function(config) {
// Your preprocessing here
MyGridPanel.superclass.constructor.apply(this, arguments);
// Your postprocessing here
}
因为Ext.extend中覆盖的属性是放在原型上的,所有constructor被赋值到
MyGridPanel.prototype.constructor,而MyGridPanel.prototype.constructor又指向MyGridPanel本身
2. MyGridPanel.superclass.constructor.apply(this, arguments); 这个确实是调用父类的构造方法
superclass不是javascript里面自带的,是在调用Ext.extend时给MyGridPanel的的运行上加的一个属性,这个属性指向父类的原型也就Ext.grid.GridPanel的原型,所以可以调用Ext.grid.GridPanel原型上的所有方法和属性。
还有这里的参数arguments可以换成传进来的config吗? 可以,如果你确定参数只有一个config,因为js中函数调用时,实参不一定等于形参的数目,所以用arguments就用的是实参。如果你确定实参只有一个可以直接用形参只不过需要用call代替apply
3. 理论上做什么都可以。一般是这样,之前可以做一些必要属性的初始话工作,比如store,columns等等,之后可以做一些和grid本身无关的一些操作
- ExtJS superclass.constructor.call(this, config)
- base.superclass.constructor.call(this,config)
- base.superclass.constructor.call(this,config)
- base.superclass.constructor.call(this,config)
- superclass.constructor.call(this,config),参数问题 [
- Extjs之superclass.constructor.call(this)之理解
- Extjs之superclass.constructor.call(this)之理解
- Extjs之superclass.constructor.call(this)之理解
- superclass.constructor.call的用法
- Extjs中的config与constructor的异同点
- Extjs grid报this.config[] is undefined
- Name、SuperClass、Constructor、Field、Method
- java.lang.VerifyError:XXX <init> signature: ()V) Constructor must call super() or this()
- C# Call another constructor in one constructor
- this、constructor、prototype
- constructor super&this
- Extjs报错:'this.config[...].width' 为空或不是对象
- js 中的this,constructor ,prototype
- MIT线性代数课程笔记对应代码-【lecture 4】
- Binary Tree Summary
- 20160303 ~/.vimrc文件
- DSP 2812: 使用C++封装定时器及应用举例
- PAT-A1075. PAT Judge (25)(排序)
- ExtJS superclass.constructor.call(this, config)
- ifdef使用
- Apache shiro 笔记整理之整合spring
- Android ListView带checkBox 实现多选模式
- NYOJ 题目171 聪明的kk
- Ubuntu14.04装好系统后,安装无线网卡
- Exynos4412 所用外存 —— eMMC
- iOS ToolBar item 间距详解
- hdu5521 Meeting最短路