JSFiddle - React, Tailwind, and code Playground
by vvakame
JavaScript
// top level
this.foo = "bar";
(function(){
alert(this.foo + " = " + window.foo);
})();
// in constructor
function Sample() {
this.foo = "bar";
}
var s = new Sample();
alert(s.foo);
// object has a ...
var obj = {foo: "bar"};
obj.func = function() {
alert(this.foo);
};
obj.func();
// injection by callee
obj = {
foo: "bar",
print: function() {
alert(this.foo);
}
};
// this pattern is object has a ...
obj.print();
var other = {foo: "inject!"};
// inject!
obj.print.call(other);