Accessor methods
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note: This feature is deprecated in favor of defining getters using the object initializer syntax or the Object.defineProperty() API. This method's behavior is only specified for web compatibility, and is not required to be implemented in any platform. It may not work everywhere.
The __defineGetter__() method of Object instances binds an object's property to a function to be called when that property is looked up.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
javascript.builtins.Object.defineGetter Deprecated | 1 | 12 | 1 | 3 | 18 | 1 |
| Built-in object | ||||||
Object.defineSetter Deprecated The _defineSetter_() method of Object instances binds an object's property to a function to be called when an attempt is made to set that property. | 1 | 12 | 1 | 3 | 18 | 1 |
Object.lookupGetter Deprecated The _lookupGetter_() method of Object instances returns the function bound as a getter to the specified property. | 1 | 12 | 1 | 3 | 18 | 1 |
Object.lookupSetter Deprecated The _lookupSetter_() method of Object instances returns the function bound as a setter to the specified property. | 1 | 12 | 1 | 3 | 18 | 1 |
- Starting with Firefox 48, this method can no longer be called at the global scope without any object. A `TypeError` will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
- Starting with Firefox 48, this method can no longer be called at the global scope without any object. A `TypeError` will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
Syntax
const user = {
firstName: 'Taro',
lastName: 'Yamada',
get fullName() {
return `${this.lastName} ${this.firstName}`;
},
set fullName(value) {
[this.lastName, this.firstName] = value.split(' ');
}
};
user.fullName; // 'Taro Yamada'
user.fullName = 'Hanako Tanaka'; Live demo
fulne-mu. autosync
and name by 々 to write and, getter to fulne-mu that automaticallyupdate..
Inputvalue. valid-tion
Setter Use, not-positive value(negative. number etc) that sett...
tax-includedprice. autocalculation
bodyprice sett and, (10%) includeprice automaticallycalculation..
Use cases
-
Using Accessor methods
Deprecated: This feature is no longer recommended.
Cautions
- Limited browser support. Check compatibility before use.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.