-1

I have an innerHTML that contains numeric or textual data that continues to flip either digits or chars according to the js automation that I've coded. Now, I'd like to use these rolling digits or chars as a flag to call other functions, and this last part without any manual interaction. To put this in other words an already automated data must in turn automate another function. How is this done?

zztops
  • 9
  • 1
  • 4

1 Answers1

1

This is how you can dynamically call functions by strings:

const dataInput1 = 'kangaroo';
const dataInput2 = 'honeybadger';

const functionCollection = new Object()

functionCollection.kangaroo = function () {
console.log('we live in Australia')
}

functionCollection.honeybadger = function () {
console.log('we are immortal')
}

functionCollection[dataInput1]()
//prints 'we live in Australia'

functionalCollection[dataInput2]()
//prints 'we are immortal'

Hope, that this is what you asked.

Martin Melichar
  • 1,036
  • 2
  • 10
  • 14
  • Yes, that certainly led to the right solution! Anyone interested in reading and rendering data as a 2 step automation (without manually interacting with a coding system) this is a great place to start. – zztops Feb 07 '20 at 00:50
  • So if it is right, could I get upvote at least? Or marking my answer as correct? You can of course create new function inside these functions and assign them to 'functionCollection', if you want to do that, I would suggest making a constructor function to create your collections, so you can easily .bind methods. – Martin Melichar Feb 07 '20 at 01:34