JSFiddle - React, Tailwind, and code Playground
JavaScript
function container() {
this.stuff = "This is the value of container.stuff";
this.otherStuff = {
stuff: "This is the value of container.otherstuff.stuff"
};
function alertThis() {
alert(this.stuff);
}
// Return "stuff"
// "this" inside the alertThis method equals the "container" function
// .. so "this.stuff" returns "container.stuff"
alertThis(); // Returns "stuff"
// Return "otherStuff"
// "this" inside the alertThis method equals the "otherStuff" object
// .. so "this.stuff" returns "container.otherStuff.stuff"
alertThis.call(otherStuff); // Returns "otherStuff":
}
container();