JSFiddle - React, Tailwind, and code Playground
JavaScript
var obj = {
val: 4
};
function foo() {
alert(this.val);
}
var bar = foo.bind(obj);
foo(); // behaves as expected; alerts `undefined` as `foo` is not attached to an object
bar(); // breaks the rules! alerts `4` because `bind()` sets `this` to `obj`.
bar.call(window); // this has no effect; still alerts `4`.