Skip to content

Commit 6de06c6

Browse files
Update blog/2024-12-05-boa-release-020/index.mdx
Co-authored-by: raskad <[email protected]>
1 parent afd9486 commit 6de06c6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

blog/2024-12-05-boa-release-020/index.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,29 @@ Boa has added support for the [stage 3 proposal `Atomics.pause`](https://github.
5252
### Getters and Setters in the js_class! macro
5353

5454
You can now add getters and setters to the `js_class!` macro. This allows you to define getters and setters on your JavaScript classes in Rust. This is a feature that has been requested by many users of Boa, and thanks to @hansl we now have it!
55-
[Point to example]
55+
```rust
56+
#[derive(Clone, Default, Trace, Finalize, JsData)]
57+
pub struct Game {
58+
score: u32,
59+
}
60+
61+
js_class! {
62+
class Game {
63+
property score {
64+
get(this: JsClass<Game>) -> u32 {
65+
this.borrow().score
66+
}
67+
68+
set(this: JsClass<Game>, new_value: u32) {
69+
this.borrow_mut().score = new_value;
70+
}
71+
}
72+
73+
constructor() {
74+
Ok(Game::default())
75+
}
76+
}
77+
}
5678

5779
### Implement your own native Errors
5880

0 commit comments

Comments
 (0)