O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required