function assert(value, desc) { var res = $("#results"); var li = document.createElement("li"); li.className = value ? "pass" : "fail"; li.appendChild(document.createTextNode(desc)); res.append(li); } Function.prototype.partial = function () { // get original function info var fn = this, args = Array.prototype.slice.call(arguments); console.log(arguments); // modify the function definition to replace all undefined arguments // we also create closure around fn and args since they are used inside the below function return function () { console.log(arguments); var arg = 0; for (var i = 0; i < args.length && arg < arguments.length; i++) { if (args[i] === undefined) { args[i] = arguments[arg++]; } } return fn.apply(this, args); }; }; assert(true, "everything is loaded"); function abc() { assert(true, "setTimeout called"); } // setTimeout called original way setTimeout(abc, 1000); // setTimeout called using currying - prefilling some of the arguments var delay = setTimeout.partial(undefined, 1000); delay(abc);
<div id="results" />
body { margin:10px; } .pass { color:green; } .fail { color:red; text-decoration:line-through; }