Moving to an OOP perspective
Our application has been developing with a growing momentum. It's time for us to stop that by changing our chart to be more OOP conducive. In this recipe we will clean up our code some more and convert some of it into objects. We will continue from where we left off in our previous recipe, Stacking graphical layers.
Getting ready
The first step is to get our latest source files: 06.01.layers.optimized.html
and 06.01.layers.optimized.js
. We will rename them and add our animation logic. Beyond changing the references on our HTML file we will not change anything else in our HTML file but focus our attention into the JavaScript file.
One of the simplest ways of creating objects in JavaScript is by using functions. We can create a function and refer within the function name to this
and by doing that we can treat the function as an object (more details in the How it works... section of this recipe).
How to do it...
Let's jump right in and start converting our code to be...