wrapper for writeable property

Posted on
  • 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

  • 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).

    Following API-description for Object.defineProperty, writeable and get/set are not supported.

    Where does it say that? Seems to say it's ok here: http://www.espruino.com/Reference#l_Obje­ct_defineProperty

  • Defining the property would loose documentation.
    And it would not be available in jswrapper.c, whatever this means at the end.
    AFAIK, calling jswrap_object_defineProperty expects a JS function for get/set, correct ?
    Let me give another example, getPixel and setPixel, myGraphics.pixel(x,y) = newColor and var pixelcol = myGraphics.pixel(x,y) , how can I do this ?
    At the end, there are lot of ways to do this, but to me it looks more elegant to set/get :-)

    Line 452 in jswrap_object.c has this in JSON-definition for defineProperty
    And it takes its way to reference you sent, see note at the end
    Note: configurable, enumerable, writable, get, and set are not implemented and will be ignored.

  • calling jswrap_object_defineProperty expects a JS function for get/set, correct ?

    Yes...

    myGraphics.pixel(x,y) = newColor

    Yes, that'd definitely be a job for jswrap_object_defineProperty. E.memoryMap actually does this right now: https://github.com/espruino/Espruino/blo­b/master/src/jswrap_espruino.c#L1697

    Line 452 in jswrap_object.c

    Thanks! I'll fix the docs

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

wrapper for writeable property

Posted by Avatar for JumJum @JumJum

Actions