Created
July 24, 2021 21:39
-
-
Save matthewoestreich/24e4e5f4340c908aec0026865e34e904 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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