how sound property not private in javascript class? additionally, how can accessed outside class? saw in video , attempted access sound property outside class , not.
class dog { constructor() { this.sound = 'woof'; } talk() { console.log(this.sound); } }
thanks!!
it's not private because can access outside after creating instance of class.
class dog { constructor() { this.sound = 'woof'; } talk() { console.log(this.sound); } } let dog = new dog(); console.log(dog.sound); // <-- // further drive point home, check out // happens when change dog.sound = 'meow?'; dog.talk();
Comments
Post a Comment