UI5 control inheritance implementation question

C同事问了我这个问题。
使用下列这段代码extend UI5标准的控件。

问题1:为什么new 一个JerryButton时,line 35会触发?
var oJerryButton = new JerryButton({ application: oApplication } );

答案:
debug extend的实现, 在line 330里把调用extend指定的constructor赋给fnClass

然后在line 352把fnClass赋给fnClass.prototype.constructor. 这样,每次用fnClass这个构造器new新的instance时,constructor指向的function会自动被call到。

问题2

为什么把constructor的赋值放到extend function外面,由application自己显式赋值,但是在new的时候却不会被调用到了?

答案:
原因是此时传入的constructor为undefine,因此fnClass也是undefine

所以line 352注入的实际上是line 346动态生成的函数体为fnBaseClass.apply的function,这样当然我们自定义的constructor不会执行了。
如果你非要想在extend外面指定constructor,怎么弄?
只需要这样:


要获取更多Jerry的原创文章,请关注公众号"汪子熙":

原文地址:https://www.cnblogs.com/sap-jerry/p/12402035.html

时间: 2024-10-22 18:49:44

UI5 control inheritance implementation question的相关文章

Table inheritance implementation changed

在AX 2012 R2我们会发现有些table是在AOT里的,但是不存在实际的SQL Database. 例如:CompanyInfo table. 最终通过Extends property,可以发现CompanyInfo table 继承的是DirPartyTable. 1. 为了研究清楚table inheritance是如何工作的,我们可以从一个小小的query开始.     CompanyInfo comp;     select generateOnly forceLiterals c

如何在SAP UI5应用里添加使用摄像头拍照的功能

昨天Jerry的文章 纯JavaScript实现的调用设备摄像头并拍照的功能 介绍了纯JavaScript借助WebRTC API来开发支持调用设备的摄像头拍照的web应用.而我同事遇到的实际情况是,需要使用SAP UI5这个前端框架来开发web应用.在有了前一篇文章的知识储备后,在SAP UI5里完成这个功能,可以采取同样的思路. 我们先回忆前一篇文章里提到的技术实现的要点: (1) 在web应用的HTML页面里定义HTML5用于显示视频的原生标签:video (2) 使用WebRTC的API

SAP UI5和微信小程序框架里的全局变量

SAP UI5 in global variable sap.ui there are many useful utility service available, such as current browser and os information. and use sap.ui.getCore().byId, we can get any UI5 control instance by its id: 微信小程序 wx for Wechat mini program is as sap.ui

.net 综合面试题

想换工作的朋友可以试着做一下:1. CLR.CTS.CLS 分别是什么意思? 公共语言运行库,通用类型系统,公共语言规范2. 什么是基元类型? 由编译器直接支持的数据类型称为基元类型. 例如:C#中的int,string等等就是,实际运行过程中被映射为FCL中对应的类型(java中叫做包装类)如:System.Int32,System.String. ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/dv_fxintro/html/7e4c5921-955d-4b

verview of Spring Framework--转

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/overview.html 2. Introduction to Spring Framework Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Sprin

wxpython wx.windows的API

wx.Window is the base class for all windows and represents any visible object on screen. All controls, top level windows and so on are windows. Sizers and device contexts are not, however, as they don't appear on screen themselves. Please note that a

Shared Assembilies and Strongly Named Assemblies

the .NET Framework has in place to deal with versioning problems. Two Kinds of Assemblies, Two Kinds of Deployment weakly named assemblies . strongly named assemblies same:use the same portable executable (PE) file format, PE32(+) header, CLR header,

SAP PA Document List

RE-Real Estate 房地产 RE010-EN-Col95-Real Estate Processes in SAP ERP RE200-EN-Col95-Real Estate Management:Implementation RE300-EN-Col95-Land Use Management in SAP Real Estate Management FICO-Finance & Controlling 财务会计成本控制 TFIN50-EN-Financial Accountin

混入和继承的区别

Mixin vs inheritance Ask Question up vote 76 down vote favorite 19 What is the difference between a mixin and inheritance? oop inheritance mixins shareimprove this question edited Jan 7 '12 at 21:18 user142019 asked May 13 '09 at 20:31 Johnd 1,958620