From the course: TypeScript: Object-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using Set

Using Set

From the course: TypeScript: Object-Oriented Programming

Start my 1-month free trial

Using Set

- So a setter or the set keyword in our class is pretty much the exact opposite of what a get is. Well, a get is there to get data, a set is there to update data while still provides some additional logic. Now, let's say when we set our isSent property, we wanted to actually have a new property here called delivery date. And delivery date will be the time associated with when that isSent property is then true, meaning we just sent it. So let's set this equal to date. Now, if we wanted to convert this to a setter getter, we can do that pretty easily and still have this functionality, right? It's going to be a bit of a hassle to every time we say, hey, go ahead and isSent update delivery date. Now, let's have our setter do that for us. So we're going to introduce some concepts here, such as access modifiers, but I'm introducing them a little bit earlier. So you can see a very practical approach of how you might use this.…

Contents