We will modify our code just a little bit to correct the missing variable using the constructor
init() method. Modify the
createObject line by adding
.init(); to the end as shown in the following highlighted line. You will find that you can tack on a method you want to call at the time of creating an object, all on the same line. This is a common method among developers. When you use a constructor, you should always return the
this variable to the caller.
this is the variable scope of an object that refers to itself and
this returns a reference to the object itself. That will correctly pass the object back when you place the constructor at the end of the creation of the object. If you look at the
init method in the ...