wrapper for writeable property #1542
Replies: 3 comments
-
Posted at 2021-05-21 by @gfwilliams I guess in the BgColor example, I'd say why not use an actual variable? But in general if you do want to do this (writable/readable) you can use jswrap_object_defineProperty as you say - but I think you'd have to make your code add the properties to the object when it was created (the 'jswrapper' stuff won't handle that for you).
Where does it say that? Seems to say it's ok here: http://www.espruino.com/Reference#l_Object_defineProperty |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-21 by JumJum Defining the property would loose documentation. Line 452 in jswrap_object.c has this in JSON-definition for defineProperty |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-24 by @gfwilliams
Yes...
Yes, that'd definitely be a job for jswrap_object_defineProperty.
Thanks! I'll fix the docs |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-05-21 by JumJum
To take Graphics as an example only.
My intention is not to change Graphics. But in myownClass it would be nice to have.
We have functions to set bgColor and to get bgColor.
Is there a way to define a writeable property in jswrap_xxx file ?
So instead of using myGraphics.setBgColor(newColor); it would be myGraphics.BgColor = newColor;
And instead of var x = myGraphics.getBgColor(); it would be var x = myGraphics.BgColor;
Following API-description for Object.defineProperty, writeable and get/set are not supported.
Hmmm, but in jswrap_object_defineProperty get and set are used to create getter and setter
Beta Was this translation helpful? Give feedback.
All reactions