JSFiddle - React, Tailwind, and code Playground

by Alexander

JavaScript

console.clear();

function Foo() {
    this._bar = 123;
}

Foo.prototype = {
    set bar (bar) {
        throw "Private property!";
    },
    get bar () {
        return this._bar;
    }
}

var foo = new Foo;
console.log(foo.bar);
foo.bar = 123;