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

https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/#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         });
复制代码

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(1024)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?
· SQL Server统计信息更新会被阻塞或引起会话阻塞吗?
阅读排行:
· 传国玉玺易主,ai.com竟然跳转到国产AI
· 本地部署 DeepSeek:小白也能轻松搞定!
· 自己如何在本地电脑从零搭建DeepSeek!手把手教学,快来看看! (建议收藏)
· 我们是如何解决abp身上的几个痛点
· 普通人也能轻松掌握的20个DeepSeek高频提示词(2025版)
历史上的今天:
2017-06-28 .net framework tools
2016-06-28 open Command window here
2016-06-28 Adding a model
点击右上角即可分享
微信分享提示