Javascript Currying
Javascript Currying - partially applying functions by prefilling some of the arguments
HTML
<div id="results" />
CSS
body {
margin:10px;
}
.pass {
color:green;
}
.fail {
color:red;
text-decoration:line-through;
}
JavaScript
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 partial() {
var extra =1;
console.log('lvl1' ,arguments);
return function () {
var args = Array.prototype.slice.call(arguments);
console.log('lvl2' ,args);
console.log('extra', extra)
};
};
assert(true, "everything is loaded");
function abc() {
assert(true, "setTimeout called");
}
// setTimeout called original way
var a = partial(abc, 1000);
a(12);
setTimeout(a(67),1000);