Simple example of javascript's bind function
by fschwiet
HTML
<div class="output"></div>
JavaScript
function Super(v) {
this.value = v;
}
Super.prototype.increment = function(amount) {
this.value += amount;
}
Super.prototype.toString = function() {
return "Super:" + this.value;
}
var s = new Super(1);
b = s.increment.bind(s);
b(2);
b2 = s.increment.bind(s,2);
b2();
document.querySelector(".output").innerText = s;