I’m just curious how this is done directly by browsers. I heard that .length property of Array in Javascript Engines in fact uses invisible setters and getters to achieve functionality of ECMA-s standard that says: ‘whenever the length property is changed, every property whose name is an array index whose value is not smaller than the new length is automatically deleted’). I understand that setter is needed in this case, but what with getter? Do we really need to call native getter to get this value? Or this is only a some mistake with understanding Javascript Engine somewhere?
Share
A property is either implemented as a field or as setter/getter methods.
If it’s a field then it’s just a value, when setting the value nothing more happens than that the value changes.
If you have a setter method in order to perform something more whenever the value is set, you also have a getter method to match, even if the getter method doesn’t do anything more than just return the value. You don’t want to mix the two ways of implementing a property, it’s just a lot simpler to go all the way in either direction.