JSFiddle - React, Tailwind, and code Playground
by slater
JavaScript
// Define a function func
var func = function() {
return this;
};
// Define an object
var obj = {
ofunc: func
} ;
// if a.func(), this represents the calling object, which is a in this case
document.writeln(obj.ofunc() === obj);
// if func(), this represents the global object, which is window
document.writeln(func() === window);
// if new func(), this represents an empty object.
document.writeln(isEmpty(new func()));
// This function test if an object is empty
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}