wiki/content/20201007093418-javascript_object_getters_setters.md

23 lines
330 B
Markdown
Raw Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-30 17:34:11 +00:00
date: 2020-10-07
2024-05-06 20:40:05 +00:00
id: 94a1d579-bd29-42f0-a6c6-2aa0700703d4
title: JavaScript object getters & setters
---
# Example
``` javascript
const obj = {
get foo() {
console.log('GET foo');
return 123;
},
set bar(value) {
console.log('SET bar to '+value);
}
};
obj.foo
obj.bar = 'tralala'
```