JSFiddle - React, Tailwind, and code Playground
by Andrew Gerst
JavaScript
simple = { value: 25 };
test = {
value: 0,
increment: function(arg){
alert(arg);
return this.value;
}
};
function bind(fnThis, fn) {
var args = Array.prototype.slice.call(arguments, 2);
return function(){
if (0 < args.length) arguments = args;
return fn.apply(fnThis, arguments);
};
}
var hey = bind(test, test.increment);
alert(hey());
var hey1 = bind(simple, test.increment);
alert(hey1());
var hey2 = bind(simple, test.increment, 'no');
hey2();
var hey3 = bind(simple, test.increment);
hey3('yes');