Variable with function name

Is there a way to store a function name in a variable then when you go to call the function use the variable rather than the function name.  The goal here is to remove all my if statements out of onupdate for optional data fields.  So if I have a data field with 10 options I can store the function name for the option the user choose outside of onupdate and then onupdate just populates the data field instead of trying to figure out what the user has chosen every time it runs.

  • See method()

    You'll see examples of this with callback functions in the API Doc for things like makeWebRequest()

    example 

    handler=method(:receiveStation);

    then to use it,

    callback.invoke(responseCode,data);

    where "callback" is set to that ("handler" from above)

  • I am finally getting around to implementing this.  I played around with this back when you gave your response and gave up after a bit.  Long story short I had all my data functions as hidden functions instead of functions and could never get it to work.  Changed them to function()...and all is well.  I am past that now and am working on properly implementing this.

    Now I have a performance/efficiency question.

    In my onupdate I am planning on setting the variable up based on the watchface options the user has picked.  The question is to just pass the function name or the full method.  One thing with the method is in the memory viewer it calls out a circular reference however in vscode itself it does not call out any circular references during the running of the watch face.

    Is there on efficiency difference between carrying the defined object and building the object each time?

    onupdate()

       myDataField1Fn = :fnData2;

    then in the main view code

       myDataField1 = method(myDataField1Fn).invoke();  

    or this approach

    onupdate()

       myDataField1Fn = method(:fnData2);

    then in the main view code

       myDataField1 = myDataField1Fn.invoke();