this._super()
https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/
https://api.jqueryui.com/jquery.widget/#method-_super
https://johnresig.com/blog/simple-javascript-inheritance/
To make the parent's methods available, the widget factory provides two methods - _super() and _superApply().
Using _super() and _superApply() to Access Parents
_super() and _superApply() invoke methods of the same name in the parent widget. Refer to the following example. Like the previous one, this example also overrides the open() method to log "open". However, this time _super() is run to invoke dialog's open() and open the dialog.
$.widget( "custom.superDialog", $.ui.dialog, {
open: function() {
console.log( "open" );
// Invoke the parent widget's open().
return this._super();
}
});
$( "<div>" ).superDialog();
proxiedPrototype[ prop ] = (function() {
var _super = function() {
return base.prototype[ prop ].apply( this, arguments );
},
_superApply = function( args ) {
return base.prototype[ prop ].apply( this, args );
};
return function() {
var __super = this._super,
__superApply = this._superApply,
returnValue;
this._super = _super;
this._superApply = _superApply;
returnValue = value.apply( this, arguments );
this._super = __super;
this._superApply = __superApply;
return returnValue;
};
})();
jquery ui widget 源码分析
//在传入的ui原型中有方法调用this._super 和this.__superApply会调用到base上(最基类上)的方法
127 $.each(prototype, function(prop, value) {
128 //如果val不是function 则直接给对象赋值字符串
129 if (!$.isFunction(value)) {
130 proxiedPrototype[prop] = value;
131 return;
132 }
133 //如果val是function
134 proxiedPrototype[prop] = (function() {
135 //两种调用父类函数的方法
136 var _super = function() {
137 //将当期实例调用父类的方法
138 return base.prototype[prop].apply(this, arguments);
139 },
140 _superApply = function(args) {
141 return base.prototype[prop].apply(this, args);
142 };
143 return function() {
144 var __super = this._super,
145 __superApply = this._superApply,
146 returnValue;
147 // console.log(prop, value,this,this._super,'===')
148 // debugger;
149 //在这里调用父类的函数
150 this._super = _super;
151 this._superApply = _superApply;
152
153 returnValue = value.apply(this, arguments);
154
155 this._super = __super;
156 this._superApply = __superApply;
157 // console.log(this,value,returnValue,prop,'===')
158 return returnValue;
159 };
160 })();
161 });
this._super()的更多相关文章
- Java修炼——继承_super父类对象的引用
Super是指直接父类对象的引用,可以通过super来访问父类中被子类覆盖的方法和属性. 当你调用子类的构造方法时,系统会默认给你先调用父类的构造方法,然后才会调用子类的构造方法. package c ...
- HTML5 学习总结(四)——canvas绘图、WebGL、SVG
一.Canvas canvas是HTML5中新增一个HTML5标签与操作canvas的javascript API,它可以实现在网页中完成动态的2D与3D图像技术.<canvas> 标记和 ...
- TypeScript之面向对象初体验
1.安装nodejs和vscode: nodejs : https://nodejs.org/en/ Visual Studio Code : https://www.visualstudio.co ...
- 基于Nuclear的Web组件-Todo的十一种写法
刀耕火种 刀耕火种是新石器时代残留的农业经营方式.又称迁移农业,为原始生荒耕作制. var TodoApp = Nuclear.create({ add: function (evt) { evt.p ...
- AlloyRenderingEngine燃烧的进度条
写在前面 Github: https://github.com/AlloyTeam/AlloyGameEngine HTML 5新增了progress标签,那么再去使用AlloyRenderingEn ...
- AlloyRenderingEngine文本框组件
写在前面 Github: https://github.com/AlloyTeam/AlloyGameEngine 在dom元素里,自带了input标签,设置其type为text,它就是一个文本框. ...
- 强大的observejs
写在前面 各大MVVM框架的双向绑定太难以观察,很难直观地从业务代码里知道发生了什么,我不是双向绑定的反对者,只是认为双向绑定不应该糅合进底层框架,而应该出现在业务代码中,或者是业务和框架之间的代码上 ...
- AlloyRenderingEngine继承
写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine然后star一下,多谢支持:). 前几天发了篇向ES6靠齐 ...
- 移动开发框架剖析(二) Hammer专业的手势控制
浏览器底层并没有给元素提供类似,单击,双击,滑动,拖动这些直接可以用的控制接口,一切的手势动作都只能通过模拟出来.移动端浏览器唯一给我们提供的就只是mousedown -> mousemove ...
随机推荐
- Mybatis-学习笔记(6)Mybatis的事务管理机制
1.什么是事务. 多个数据库原子访问应该被绑定成一个整体,这就是事务.事务是一个最小的逻辑执行单元,整个事务不能分开执行,要么同时执行,要么同时放弃执行. 事务的4个特性:原子性.一致性.隔离性.持续 ...
- 跟风Manacher算法整理
这是上上周天机房一位神仙讲的,\(gu\)了这么久才来整理\(w\),神仙讲的基本思路已经全都忘记了,幸好的是神仙写了\(blog\),吹爆原博浅谈\(Manacher\)算法,以及原博神仙\(ych ...
- HNUSTOJ-1675 Morse Code(DFS+字典序搜索)
1675: Morse Code 时间限制: 2 Sec 内存限制: 128 MB提交: 73 解决: 33[提交][状态][讨论版] 题目描述 摩尔斯电码(英语:Morse Code)是一种时通 ...
- Self-Driving Database
最近一直在做 ML in Database 相关的工作.偶然发现CMU 19spring的15-721课程竟然专门安排了这个专题,不禁欣喜若狂,赶紧去学习了一下. Andy提出了self-drivin ...
- 出去就餐并且理解Express.js的基本知识
Going out to eat and understanding the basics of Express.js出去就餐并且理解Express.js的基本知识 原文:Going out to e ...
- 95-基于FMC接口的2路CameraLink Base输出子卡模块
基于FMC接口的2路CameraLink Base输出子卡模块 1.板卡概述 FMC连接器是一种高速多pin的互连器件,广泛应用于板卡对接的设备中,特别是在xilinx公司的所有开发板中都使用.该Ca ...
- 下载xlsx文件打开一直提示文件已损坏
这是office受保护视图导致的原因所造成的,按照以下操作,问题就不是问题了 解决办法如下: 1.在打开excel2018数据表格时,出现提示“文件已损坏,无法打开”,点击确定按钮 2.进入空白程序界 ...
- 使用量产工具合并U盘空间一例
1.问题提出: 朋友拿到一只别人赠送的广告U盘,上面印刷有产品广告.插入电脑后,在系统的磁盘管理中,显示为两块“硬盘”,其中一块“硬盘”中有广告视频.产品介绍等,占用大概6GB,这块“硬盘”中的这 ...
- 《Java核心技术卷I》——第3章 Java的基本程序设计结构
byte和short类型主要用于特定的应用场合,例如,底层的文件处理或者需要控制占用存储空间量的大数组. 十六进制数值有一个前缀0x(如0xCAFE),八进制有一个前缀0,如010对应八进制中的8.很 ...
- 10年前文章_eclipse下perl环境搭建
eclipse下perl环境搭建1.Eclipse下安装perl插件Help -Software Updates…- Available .- Add Site… :http://e-p-i-c ...