Infusion code generally follows a few conventions that we recommend, and that we'll use in this tutorial. We'll start with two of them:
We define a namespace for our code: a single global variable that becomes the container for the code. This helps keep code contained, meaning there's less chance of bad interactions with other code: Anything we want to be public will be attached to this object, so all of our code will be qualified by the namespace.
By wrapping the rest of the code inside an anonymous function, we can separate private and public functions. Only objects or functions that are attached to the global namespace object will be publicly available. Anything else inside the anonymous function will be invisible to the rest of the world.
So what does this look like in general?
The parameters to the anonymous function,
fluid, will be used as shorthand for the arguments that were passed in:
fluid_1_4 respectively. This allow us, for example, to upgrade to the next version of Infusion (e.g.
fluid_1_5) simply by changing the one argument, instead of having to change every single use of the word
So what might this look like in the real world? Well, for our bar graph example, we might call the global namespace
visualizer and create a public function called
barGraph that can be used by anyone to instantiate a bar graph component: