O'Reilly logo

Building HTML5 Games with ImpactJS by Jesse Freeman

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

How Inner Classes Work

In traditional class-based languages, you usually have the option to put a class inside of another class’s package structure. These are called inner classes. Impact has its own version of this, which allows us to add more than one class to a single module file.

Creating an inner class is similar to making a normal class, with the exception that you will be adding it to the end of the main class’s module. These inner classes also support inheritance as well. Here is a quick example of two classes in the same module:

1    ig.module(
2        game.entities.myclass'
3    )
4    .requires(
5        'impact.entity'
6    )
7    .defines(function(){
8        EntityMyClass = ig.Entity.extend({
9            //Properties and methods go here
10        });
11
12        EntityMyInnerClass = ig.Entity.extend({
13            //Properties and methods go here
14        });
15    });

This technique is incredibly helpful when it comes to keeping your code organized, as you will see later in the book.

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