DEV Community

loading...

Discussion on: Classes in JS: Public, Private and Protected

Collapse
shadowtime2000 profile image
shadowtime2000 • Edited

For protected variables you could also kind of use what was used for private variables with a function.

function NameGenerator(name) {
var publicData = {name};
var privateData = publicData;
Object.freeze(publicData);
return {...publicData, john() {return NameGenerator("John")}};
}

Though I don't have any good idea on how to actually change the values instead of creating a new object;

Forem Open with the Forem app