JSFiddle - React, Tailwind, and code Playground
by evgkch
JavaScript
// Define private property
// Requred args: prop, value
// Descriptor: configurable - false, enumerable - false, writable - true, get - undefined, set - undefined
function definePrivate(prop, value){
Object.defineProperty(this, prop, {
value,
writable: true
});
}
class Ex {
constructor(){
definePrivate.call(this, '_hidden', 1);
}
}
const a = new Ex();
console.log(a)