JSFiddle - React, Tailwind, and code Playground
JavaScript
// A function not bound to anything. "this" is the Window (root) object
var unboundFn = function() {
console.log('unboundFn: ' + this);
};
unboundFn();
// A function that is part of an object. "this" is the object
var partOfObj = function() {
console.log('partOfObj: ' + this.someProp);
};
var theObj = {
"someProp": 'Some property',
"theFn": partOfObj
};
theObj.theFn();
// A function that is bound using .bind(), "this" is the first parameter
var boundFn = function() {
console.log('boundFn: ' + this.someProp);
};
var boundFn = boundFn.bind(theObj);
boundFn();