Foundations.Class

This namespace contains a method for creating classes.


Class.create()

Creates class objects that can call their own initialize (contructor) methods.

If the first argument is a class, it is treated as the new class's superclass, and all its methods are inherited. Otherwise, any arguments passed are treated as objects, and their methods are copied over as instance methods of the new class.

Syntax

    Class.create(superclass, methods);

Parameters

Argument Required Type Description
superclass No object If no superclass, the passed methods are used in creating the new class.
methods No objects Methods to implement. If nothing is passed, methods are inherited from the superclass. Methods passed override methods in the superclass.

Returns

{
  Class Object
}

Example

var libraries = MojoLoader.require({ name: "foundations", version: "1.0" });
var Class = libraries["foundations"].Class; 
var Pet = Class.create(  {
  //our 'constructor'
  initialize: function(petName, age){
      this.name = petName;
      this.age = age;
  },

  log: function(){
      Mojo.Log.info("I do not know what I should say, but my name is " + this.name);
  }
});

var famousDog = new Pet("Santas Little Helper", 15);
famousDog.log();

Example Output

I do not know what I should say, but my name is Santas Little Helper