mcaz
8/9/2019 - 9:24 AM

Getter/Setter

function Sample(val) {
    return {
        val: {
            get() {
                console.log('getter');
                return this.val;
            },
            set(val) {
                console.log('setter');
                this._val = val;
            }
        }
    };
}

const sample = Sample(10);

sample.val = 999;