JavaScript Setter (The set Keyword)
Example: This example describes the use of the lang() property to set the value of the language property.
Javascript
// Create an object: const person = { name: "w3wiki" , set lang(value) { return this .name; } }; // Display data from the //object using a getter console.log(person.name); |
Output
w3wiki
Note: Getters and Setters are not supported in Internet Explorer 8.
JavaScript Object Accessors
There are two keywords that define the accessors functions: a getter and a setter for the fullName property. When the property is accessed, the return value from the getter is used. When a value is set, the setter is called and passed the value that was set.
Contact Us