Last active
August 29, 2015 14:03
-
-
Save Enelar/4b459173b8b895b50265 to your computer and use it in GitHub Desktop.
Javascript load every function call
This file contains 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
function HookObject(hook, depth) | |
{ | |
var k, fn; | |
if (typeof depth === 'undefined') | |
depth = -1; | |
// https://gist.github.com/Enelar/34f9ef9ee412cb88beb4 | |
var _CloneObject = CloneObject; | |
function Helper(name, fn) | |
{ | |
var args = [name, fn]; | |
return function() | |
{ | |
args[2] = _CloneObject(arguments); | |
if (hook.apply(this, args)) | |
return fn.apply(this, arguments); | |
} | |
} | |
for (k in this) | |
{ | |
fn = this[k]; | |
if (typeof fn === 'object' && !depth) | |
HookObject.call(fn, hook, depth - 1); | |
if (typeof fn !== 'function') | |
continue; | |
this[k] = Helper(k, fn); | |
} | |
} | |
HookObject | |
( // Hook whole document.window | |
function(name, fn, args) | |
{ | |
console.log("Hook", name, args); | |
return true; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment