Accessor properties

Accessor properties

They are essentially functions that work on getting and setting a value, but look like regular properties to an external code.

Getters

Syntax

  get propName() {
    // getter, the code executed on getting obj.propName
  }

Setters

Syntax

set propName(value) {
    // setter, the code executed on setting obj.propName = value
  }

Accessor properties — Structure map

Clickable & Draggable!

Accessor properties — Related pages: