Time for action – implementing a reusable toolbar

Now let's create a new reusable Toolbar object that encapsulates the code for a toolbar. That way we can also use it in our other applications later on. We will put it inside a new file called toolbar.js. The constructor will take the root element of the toolbar wrapped in a jQuery object:

function Toolbar($toolbar)
{
    var _this = this;

Remember how I said in Chapter 1, The Task at Hand that the this pointer can cause problems when using event handlers with public methods? To get around that we will create a global _this variable and set it to the object's this so it's always available.

First we will implement the public methods. We have two methods that are used to notify the application that either ...

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.