Angular应用里setTimeout被如何被monkey patched的

Angular应用里setTimeout被如何被monkey patched的

Angular应用里setTimeout被如何被monkey patched的

Angular应用里setTimeout被如何被monkey patched的

Zone.__load_patch('timers', (global) => {
        const set = 'set';
        const clear = 'clear';
        patchTimer(global, set, clear, 'Timeout');
        patchTimer(global, set, clear, 'Interval');
        patchTimer(global, set, clear, 'Immediate');
    });
    Zone.__load_patch('requestAnimationFrame', (global) => {
        patchTimer(global, 'request', 'cancel', 'AnimationFrame');
        patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame');
        patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame');
    });
    Zone.__load_patch('blocking', (global, Zone) => {
        const blockingMethods = ['alert', 'prompt', 'confirm'];
        for (let i = 0; i < blockingMethods.length; i++) {
            const name = blockingMethods[i];
            patchMethod(global, name, (delegate, symbol, name) => {
                return function (s, args) {
                    return Zone.current.run(delegate, global, args, name);
                };
            });
        }
    });

然后我在Angular应用里调用setTimeout时,执行的实际上是被monkey patched之后的版本,即代码1449行的函数体 patchDelegate, 一个委托函数:

Angular应用里setTimeout被如何被monkey patched的Angular应用里setTimeout被如何被monkey patched的

上一篇:Android笔记:android.view.WindowManager$BadTokenException错误解决方法


下一篇:快速构建Windows 8风格应用12-SearchContract概述及原理