Created
September 28, 2015 20:47
Revisions
-
sir-ragna created this gist
Sep 28, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ /* A function that give the first argument to the callback function */ function wrapper(func) { return function(arg1, callback) { func(arg1, function() { callback(arg1); }); }; } function bar(arg1) { console.log("Bar: " + arg1); }; function foo(arg1, callback) { console.log("Foo: " + arg1); callback(); }; // Test the wrapper var fooImproved = wrapper(foo); fooImproved("Hello", bar); /* Now lets add logging for all arguments */ function addArgLogging(func) { return function() { for(var i = 0; i < arguments.length; i++) { // If your arguments contains more then strings // Say functions then you should add a check for that // here console.info("ARG " + i + ": " + arguments[i]); } func.apply(this, arguments) }; } // Test the Arg logger var barLogged = addArgLogging(bar); barLogged("Test", "Hello", "World", "Hey!");