Chapter 1 - InitialClassLibrary ReturnsFunction
by GarethElms
JavaScript
var Class = function()
{
var _class = function( name)
{
console.log( "...creating a new Person");
this.name = name;
this.init.apply( this);
};
// Create an instance method to _class.
_class.prototype.init = function() {};
// Return the _class object.
return _class;
};
console.log( "Person class defined");
// Setup our base class which contains an init function in its prototype
var Person = new Class();
console.log( "Person base class instantiated");
Person.prototype.init = function()
{
console.log( "...calling init() on a Person instance");
}
console.log( "About to call : var person = new Person( \"gaz\");");
var person = new Person( "gaz");
console.log( "...person.name is '" + person.name + "'");