Create readonly property from constructor argument in custom class? #4308
-
What I'm trying to do is start with something like the classes example:
But have, for example, the The Person example has code to set a readonly property:
But that's using a hardcoded value, whereas I want the value from the constructor (like 'John' above). Based on a previous discussion and example code from the docs, I tried the following:
This results in a JavaScript runtime error: "cannot set non-writable property: name" If I comment out the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @tomoverlund 👋 Instead of using boa/core/engine/src/object/operations.rs Lines 235 to 243 in 3700a94 false and that should do it 😄 )
NOTE: You don't need Hope that helps :) |
Beta Was this translation helpful? Give feedback.
Hi @tomoverlund 👋
Instead of using
.set()
which has implicit writable use the.define_own_property_or_throw()
, with aPropertyDescriptor
(here is an example usage of itboa/core/engine/src/object/operations.rs
Lines 235 to 243 in 3700a94
false
and that should do it 😄 )NOTE: You don't need
class.property
for that property, what class.property does is install…