JSFiddle - React, Tailwind, and code Playground
JavaScript
function bind1(func, obj) {
var self = func, context = obj;
return function() {
return self.apply(context, arguments);
}
}
window.x = 1;
var ctx = {x:2};
function testThis(a) { console.log("x=" + this.x + ", a=" + a); }
console.log(testThis(100)); // x=1, a=100
var boundFunction = bind1(testThis, ctx);
console.log(boundFunction(100)); // x=2, a= 100