Limited supportLimited support. Check browser compatibility before use.

Overview

The __defineGetter__() and __defineSetter__() methods of objects bind a function to a property, which is called on setting or reading the property.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
3
18
1
Built-in object

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

The _lookupGetter_() method of Object instances returns the function bound as a getter to the specified property.

1
12
1
3
18
1

The _lookupSetter_() method of Object instances returns the function bound as a setter to the specified property.

1
12
1
3
18
1
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
  • 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.
Notes 1 item(s)
Implementation note
  • 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

JAVASCRIPT
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..

PreviewFullscreen

Inputvalue. valid-tion

Setter Use, not-positive value(negative. number etc) that sett...

PreviewFullscreen

tax-includedprice. autocalculation

bodyprice sett and, (10%) includeprice automaticallycalculation..

PreviewFullscreen

Use cases

  • Using Accessor methods

    The __defineGetter__() and __defineSetter__() methods of objects bind a function to a property, which is called on setting or reading the property.

Cautions

  • Limited browser support. Check compatibility before use.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features