利用ES6里标准化的JavaScript proxy对象拦截SAP C4C页面的HTML div原生操做

SAP Cloud for Customer的UI实现里,有很多使用JavaScript在运行时动态建立div标签的例子。浏览器

若是想研究这些情形发生的上下文,咱们可使用ES6提供的标准Proxy对象,给浏览器原生的document.createElement方法注入一个proxy,里面设置一个断点。这样每当div标签页被动态建立时,咱们注入的proxy将会取代标准的document.createElement被浏览器调用。从断点停下来的调用上下文,咱们便可观测到更多信息。app

const handler = { // Our hook to keep the track
    apply: function (target, thisArg, args){
        console.log("Jerry Intercepted a call tocreateElement with args: " + args);
        debugger;
        return target.apply(thisArg, args)
    }
}
document.createElement= new Proxy(document.createElement, handler);

好比每次SAP Cloud for Customer UI出现busy indicator的动画效果时,其实浏览器就是残躯新建一个div标签的方式实现的。动画

使用setTimeout实现busy indicator的动态效果。this



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

相关文章
相关标签/搜索