Use getters and setters to control access to an Object in javascript |#javascript | #Revildo_code

preview_player
Показать описание
Use getters and setters to control access to an Object in javascript | Javascript Full Course |#javascript | #Revildo_code

Getter functions are meant to simply return (get) the value of an object's private variable to the user without the user directly accessing the private variable. Setter functions are meant to modify (set) the value of an object's private variable based on the value passed into the setter function

In JavaScript, accessor properties are methods that get or set the value of an object. For that, we use these two keywords: get - to define a getter method to get the property value. set - to define a setter method to set the property value.

JavaScript Accessors (Getters and Setters)

ECMAScript 5 (ES5 2009) introduced Getter and Setters. Getters and setters allow you to define Object Accessors (Computed Properties).

Getters give you a way to define a property of an object, but they do not calculate the property's value until it is accessed. A getter defers the cost of calculating the value until the value is needed. If it is never needed, you never pay the cost.

Getters and setters allow us to define Object Accessors. The difference between them is that the former is used to get the property from the object whereas the latter is used to set a property in an object.

#javascript #javascript_2020 #javascript_basics #javascript_course #javascript_crash_course #javascript_developer #javascript_full_course #javascript_project #javascript_promises #javascript_tutorial #javascript_tutorials #learn_javascript #learn_javascript_for_beginners
Рекомендации по теме