SAP UI5 Diagnostics工具里一个使用面向切片编程(AOP)的一个例子
We know that UI5 framework provides a convenient Diagnostics tool for application developer to set breakpoint on a given method of control class. The Diagnostics tool could be launched via Ctrl+Alt+Shift+S.
We can select the control and its methods where we would like to set breakpoint. Once we click “Add breakpoint” button, next time if the corresponding method is called, the breakpoint would be triggered, without application developers’ manual set in Chrome development tool any more.
It looks like a magic? Today my colleague asked me how this feature is implemented, so I have a look at UI5 framework source code. We can again simply use Chrome development tool for research.
For example I would like to set breakpoint on method _bindAggregation:
Here the AOP idea is used.
The hook implementation is simply returning a new function via closure within which the original method is called ( line 521 ) with the new feature injected via keyword debugger.
After the logic is understood, we can practice in our application code.
Suppose I would like to have my button press event handler supported by this mechanism, I can simply write the following pseudo code:
var myButton = new sap.ui.commons.Button("btn",{
text: "press me~"
});
var handler = function(oEvent){
oController.onPress(oEvent);
};
handler = bDebugModeActivated? util.tool.methodHook(handler): handler;
myButton.attachPress(handler);
In the runtime, once I press the button, debugger will be triggered with the following callstack:
Just step into line 36:
and then our event handler could be debugged:
- Spring/Hibernate 应用性能优化的7种方法
- 浅谈应用型机器学习作为一种搜索问题
- 自相关和偏自相关的简单介绍
- 机器学习中分类与回归的差异
- 自然语言处理指南(第1部分)
- GreenDao 兼容升级,保留旧数据的---全方面解决方案
- 基于 xorm 的服务端框架 XGoServer
- 全面总结: Golang 调用 C/C++,例子式教程
- 架构之路(六):把框架拉出来
- 第二届游戏运营技术论坛——云时代的游戏运营之道
- 如何才能准确测量 APP 的功耗?
- 可用性更高:设计优秀的MySQL和Percona XtraDB集群
- 如何使用scikit-learn在Python中生成测试数据集
- OpenStack Neutron之持续测试
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 浅谈php使用curl模拟多线程发送请求
- PHP模型Model类封装数据库操作示例
- 解决django migrate报错ORA-02000: missing ALWAYS keyword
- PHP封装的数据库模型Model类完整示例【基于PDO】
- PHP的简单跳转提示的实现详解
- PHP多进程通信-消息队列使用
- PHP implode()函数用法讲解
- PHP精确到毫秒秒杀倒计时实例详解
- django 装饰器 检测登录状态操作
- 使用PyWeChatSpy自动回复微信拍一拍功能的实现代码
- Django Session和Cookie分别实现记住用户登录状态操作
- 使用PHPUnit进行单元测试并生成代码覆盖率报告的方法
- PHP封装XML和JSON格式数据接口操作示例
- 浅谈PHP进程管理
- php使用fullcalendar日历插件详解