DevTips Daily: How to use getters and setters in TypeScript

preview_player
Показать описание
⭐️ Check out more DevTips Daily ⭐️

#devtipsdaily Channel Handle @codebubb
Рекомендации по теме
Комментарии
Автор

Hi codebubb, and thank you for this series. It is perfect. 2 minutes and you pass the message ! Now i meant to ask you something. When you use the getter what happens when you try and mutate what the getter returns? I think if it is a basic type like number or string you cant mutate the property of the object in this way, but if the getter returns a property value that is an object it essentially returns a reference to that object which can be in turn mutated by the outside calling code. Am i correct and if so, what is the best practice to avoid that from happening? I keep cloning my objects because i dont want users writing code calling my modules to mutate them by accident. Many thanks
!

athanasiosagiannidis
visit shbcf.ru