About function context

In our app, we don’t need to provide any API for other libraries to use. So we dont need global variable at all.

How to make the app zero global variables?

From 1 global variable to 0.

1(function(){
2  var hello = "world";
3  this.name = "Thomas";
4})();

1 global variable: name.

1(function(){
2  var hello = "world";
3  this.name = "Thomas";
4}).call(this);

1 global variable: name.

1var scope = {};
2(function(){
3  var hello = "world";
4  this.name = "Thomas";
5}).call(scope);

1 global variable: scope.

1(function(){
2  var scope = {};
3  (function(){
4    var hello = "world";
5    this.name = "Thomas";
6  }).call(scope);
7})();

Now, 0 global variables.

The same can apply to our TwentyFive app.

We have a global variable tf that works as a glue among different components. We can wrap all the code into a self-invoked-anonymous-function. And then executed all the components anonymous function by our desired context. For detail, please check the example code on this topic. And you can try the demo here although you will find no different on the visual part.

What’s next? We’re going to take a look at “TouchStart and TouchEnd event”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content