JSFiddle - React, Tailwind, and code Playground
JavaScript
function Example() { //There is no length property
this.foo = 0.2;
this.getFoo = function() {
return foo;
}
}
function ExampleTwo() {
this.length = 0; //A public length property is provided
}
Object.defineProperty(Object.prototype, 'c', { //Demonstration with Object.prototype, showing potential caveats
get: function() {
return this.length;
}
});
alert(new Example().c); //Here, the c property returns undefined because Example has no length property!
alert(new ExampleTwo().c); //Yields 0