dynamically generate function in object #1449
Replies: 4 comments
-
Posted at 2021-01-22 by @gfwilliams
This is quite a common thing. The code itself is stored and executed as-is, but the variable The usual solution for this is to use
Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-01-23 by @allObjects @gfwilliams, you say in other words that because in line #1 a new code-object - reference-object m (pointing to/referencing related machine object) - is created and then used in a function code-object and held in the array, the reference to m is held on to until the whole menuObject disappears / garbage collected... (Btw, since menuObject is not declared in function, its first use declares it as global and it survives the end of showMenu() function, and stays alive until set again as a new object ( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-01-23 by @fanoush
the function inside You would need to store value of tempArray[i] into the menuObjekt or somewhere else directly in the loop. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-01-23 by Primata Hey, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-01-21 by Primata
Hello,
I am trying to create a Bangle.js app for my gym training plan.
I have an interface for the app loader where I create the training plan, this is an Array of json objects.
Now I want to create a menu, where I can select a machine which has not been finished.
The keys are shown correct, but the function to get the settings view does not work.
The output for consol.log(mainmenu); is:
Why is the index not replaced?
I tried a lot of stuff, but don't understand my problem.
Neither my programming skills nor my English are very good, so I don't get the problem.
The web ide is warning me, that functions declared within loops may lead to confusing semantics, but I don't see another way?
There may be a different amount of machines I want to train, and I want only the machines to be in the machines I haven't finished.
Thank you in advance for your help and patience.
Tobi
Beta Was this translation helpful? Give feedback.
All reactions