Skip to content

Instantly share code, notes, and snippets.

@matthewoestreich
Created July 24, 2021 21:39
Show Gist options
  • Save matthewoestreich/24e4e5f4340c908aec0026865e34e904 to your computer and use it in GitHub Desktop.
Save matthewoestreich/24e4e5f4340c908aec0026865e34e904 to your computer and use it in GitHub Desktop.
class House {
constructor() {
this.rooms = [];
}
getRooms() {
return this.rooms;
}
addRoom(name, props) {
this.rooms.push({ name, props });
}
}
const myHouse = new House();
// This is what you want ppl to do
myHouse.addRoom('master', { sqFt: 300 });
// The problem is, what's stopping someone
// from doing this?
// No private fields in JS..
myHouse.rooms.push("i am just a string");
console.log(myHouse.rooms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment