Skip to content

Instantly share code, notes, and snippets.

@Enelar
Last active August 29, 2015 14:03
Show Gist options
  • Save Enelar/4b459173b8b895b50265 to your computer and use it in GitHub Desktop.
Save Enelar/4b459173b8b895b50265 to your computer and use it in GitHub Desktop.
Javascript load every function call
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