Created
May 5, 2016 11:22
-
-
Save kdziamura/9aa265333bb678a164a4c53758a900ca to your computer and use it in GitHub Desktop.
setTimeout debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((global, _log = console.log.bind(console)) => { | |
function log(id, methodName, desc) { | |
_log(`TIMER #${id}: ${methodName} - ${desc}`); | |
} | |
global.setTimeout = (setTimeout => (callback, timeout, ...params) => { | |
const id = setTimeout((...params) => { | |
log(id, 'setTimeout', 'create call stack'); | |
callback(...params); | |
log(id, 'setTimeout', 'end of call stack'); | |
}, timeout, ...params); | |
log(id, 'setTimeout', `schedule call of ${callback.name || '<anonymous>'}`); | |
return id; | |
})(global.setTimeout); | |
global.clearTimeout = (clearTimeout => (id) => { | |
log(id, 'clearTimeout', 'remove call from queue'); | |
return clearTimeout(id); | |
})(global.clearTimeout); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment