A getter
is a method that retrieves the value of a particular property, while a setter
is a method that sets the value of a specific property.
getter
and setter
, interception operations for data retrieval and assignment can be implemented. When you want to monitor the change of a value, you can achieve this through getter
and setter
without having to find and modify every piece of code that operates this value.getter
and setter
.getter
and setter
can be combined to create a pseudo-property, it is not possible to bind getter
and setter
to a property that actually has a value.You can directly declare get
and set
methods when creating objects through literals.
Use Object.defineProperty()
to precisely add or modify an object's properties.