0

i made this code to overwite all the window function and put a console.log after the function run but it giving me error what is the prob??

Uncaught TypeError: Not enough arguments

for (func in window) {
    if (typeof window[func] === 'function' && typeof window[func] != 'undefined') {
        var s = window[func];
        window[func] = function (a) {
            s(a);
            console.log(func);
        }
    }
}

alert("hehe");
VisioN
  • 143,310
  • 32
  • 282
  • 281
  • 1
    http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example – DCoder May 13 '13 at 10:18

1 Answers1

1

As another poster mentioned, the problem is that your variable s is getting overwritten each time through the loop. Instead, try

function overwrite(f){
    return function(a){
        var ret=f(a);
        console.log(f);
        return ret;
    };
}

for (func in window) {
    if (typeof window[func] === 'function' && typeof window[func] != 'undefined') {
        window[func]=overwrite(window[func]);
    }
}

alert("hehe");