Facility Control

 View Only
  • 1.  javascript objects

    Posted 06-04-2020 20:59

    i'm taking a course on object oriented programming, and i understand that javascript is kind of a bit unique to most obj oriented languages, because almost everything is an object in a sense. still, it got me wondering if I could make my code more organized, more efficient, and reusable if i used more organized objects. i mean i can clearly make an object inside the task of a parameter, but does that object get cleared out of memory as soon as the task is completed? bc i cant seem to access my objects from one param's task to another. im assuming this has to do with scope, but i cant seem to figure out where i should write the code at the "bottom" level where all the other params can see/access it. if this is considered a bad idea or not possible, then i'd appreciate some programming theory advice here about ogScript. thanks.



  • 2.  RE: javascript objects

    Posted 06-05-2020 13:33

    Hi Roger

    You're absolutely correct that making use of objects and functions is a great way to reuse code around your panel and keep things better organized.

    You have also correctly identified the issue with creating them inside of a parameter's task. The scope is limited to that parameter (consider variables and functions declared here to be inside of a private function). 

    The <api/> tag is intended as a place for you to put all of your global variables and functions. If you put an <api/> tag near the top-level of your custom panel (they also follow a hierarchy), you will be able to see all of your objects and functions inside of your other <ogscript/> blocks and parameter/button tasks. One trick that can sometimes be helpful with using these is to check the "execute immediately" box to have its ogScript evaluated as soon as the processor hits that tag instead of waiting until the rest of the panel is loaded.

    Another option you have available to access things outside of scope in a parameter or button task is to use ogscript.putObject(KEY, VALUE) and ogscript.getObject(KEY) to pass things around. This map is scoped at the panel-level as opposed to the task level.

    Hope this helps you get going.

    Cheers

    James


    #DashBoard


  • 3.  RE: javascript objects

    Posted 06-08-2020 12:40

    thank James. This is a big help.


    #DashBoard