// A few functions with some calls between them
var obj = { someCoolFunction: function () { // Do some action
},
anotherFunction: function () { // Do some action
},
thirdFunction: function () { // Do some action
obj.anotherFunction();
},
fourthFunction: function () { // Call anotherFunction and someFunction
obj.anotherFunction();
obj.someCoolFunction();
},
allFunction: function (e) {
obj.someCoolFunction(e);
obj.anotherFunction(e);
obj.thirdFunction(e);
obj.fourthFunction(e);
}
}
function WrapFunctions() {
// Run over all objects in the obj
for (fnc in obj) {
if (typeof obj[fnc] == "function") {
var currentelement = $("#debuglog");
(function (originalFnc, name) {
// Redefine the function
obj[fnc] = function () {
// Write the function name in an LI and nest
// deeper function calls in a UL
var fncItem = $("<li>Called " + name + "</li>")
var newparent = $("<ul></ul>");
currentelement.append(fncItem.append(newparent));
var olditem = currentelement;
currentelement = newparent;
// Call the original function
originalFnc.call(this, arguments);
// Reset the current container
currentelement = olditem;
};
})(obj[fnc], fnc); // Pass in the original function and its name
}
}
}WrapFunctions();
$("#btnAction1").click(obj.someCoolFunction);
$("#btnAction2").click(obj.anotherFunction);
$("#btnAction3").click(obj.thirdFunction);
$("#btnActionAll").click(obj.allFunction);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.