There is a new shorter syntax for adding methods and properties to Objects in ES6. This video covers that new syntax as well as how you can add getter and setter methods for your object properties.
This video is still helping someone 3 years in the future understand JS a bit better. Thank you, Steve!
ihvtework
Thank you very much. Day by day, with every other your tutorial I found JS is not that formidable as before.
rotrose
What an awesome tutotial! Keep them coming!
Pharizer
Thank you very very much, it was like a flashlight in my brain. Finally, I could understand Getter and Setters!!!!
marcoscabrinirianidosreis
Awesome job! I was having trouble understanding Getters and Setters, but it makes sense now.
bretthoppough
Easy to understand and straight to the point, appreciate your explanation very much
!
kenho
Finally getter and setter make sense now. You rocks!
yehfang
You are a great teacher. Thank you for making these clear and helpful videos.
joebuono
Thank you Steve! I am happy that I found your channel. You are helping me a lot! Cheers!
maj
This is a great explanation, yet I really don't see much use of it. We could also access object property directly like obj.prop1 This encapsulation feeling is false because object properties are not really hidden like in real OOP environment. We can access them anyway. But as I said great explanation, thanks
adriatic
Thank you so much. It finally makes sense. Keep up the good work👌
yonisomar
thanks for the video! Greatly explained !
igorking
Thank you for the video. I have a quick question - Why use a getter? Could you not just write a 'normal method' that returned the value in prop1 * 2?
Can you please tells us where we can use these getters and setters in real-world applications!
fahadhafeez
I haven't tested this yet, but normally when creating an object literal, all properties are public by default. If I remember correctly, there is no way of creating private fields in an object literal unless you change to a function constructor and use const/let for internal properties without using the this keyword or just use object descriptors. Does creating a getter and setter automatically creates the fields private? Also, what is the difference of creating a getter and setter vs plain methods that can return and set an object properties?
PS-dpyg
4:57 why don't we have to add '()' while calling the prop4 method in the obj unlike other methods in an object where we should add () to get the returned result
and why do I get an error when I call it with '()' like this obj.prop4()
romeojoseph
sir we cannot use set method separately like
let obj={
a:1979,
set c(_v){
this.a=_v;
},
prop3(){
console.log('prop3 called')
}
};
noaakshay
Hi Steve,
Thanks for the video! There are actually 2 things I don't get.
1. When I work in Java I usually just create a method called getValue() or setValue(). Why do we need the special keywords here?
2. Also, if the _prop1 is hidden from others, what's the point of still being able to set it?
Thanks for your answer in advance!
korhad
what if we write like obj.prop1(1980) in our setter function
romeojoseph
isn't it true that you can always view the javascript code (unless you're running it on a server via node)? If that's the case, you can alter the value of a variable without using the getters and setters right? So how are they then protected?