Class Index | File Index

Classes


Namespace Class

Global namespace for class related functions.
Defined in: jstraits.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global namespace for class related functions.
Method Summary
Method Attributes Method Name and Description
<static>  
Class.define(o)
Define a new class.
Namespace Detail
Class
Global namespace for class related functions.
Method Detail
<static> {Function} Class.define(o)
Define a new class. In the traits model of object oriented programming a class consists of: This structure is directly mirrored in the argument structure of Class.define.

A number of special properties are assigned to the class at definition time:

Conflicts among instance properties are resolved in the following order: class members override trait members and superclass members, and trait members override superclass members.

The class constructor is specified as a method named init passed into the o.members argument.

var HappyFace = Class.define({
  superclass: Doodle,
  uses: [
    TFace,
    TColoredCircle.aliases({drawColoredCircle: 'draw'})
  ],
  members: {
    // constructor
    init: function(color) {
      this.isDrawn = false;
      if (color)
        this.setColor(color);
    },
    // draw a happy face
    draw: function() {
      // call Doodle's draw method to set up the canvas
      this._super();
      // draw a colored circle
      this.drawColoredCircle();
      // draw the face
      this.drawEyes();
      this.drawMouth():
      // record that the happy face has been drawn
      this.isDrawn = true;
    },
    // color of the happy face (default is yellow)
    color: 'yellow',
    getColor: function() { return this.color },
    setColor: function(color) { this.color = color }
  }
});

// draw a blue happy face
var hf = new HappyFace('blue');
hf.draw();
log(hf.isDrawn); // => true
log(hf.does(TFace)); // => true
log(HappyFace.does(TColoredCircle)); // => true
log(HappyFace.superclass === Doodle); // => true
Parameters:
{Object} o
The class configuration object.
{Function} o.superclass Optional
Superclass from which this class inherits. Default superclass is the global object Class.
{Trait|Trait[]} o.uses Optional
A list of traits that will be composed into this class. This happens by first constructing a new anonymous trait and then adding each of that anonymous trait's exported methods into the class prototype. Trait methods are not copied, however, if there is a method defined at the class level with the same name (because class level methods override trait level methods). Unlike normal trait definition, all trait requirements must be fullfilled at class definition time, either by one of the composed traits, a class method, or a superclass method. See the documentation for o.uses in Trait for full details on how to specify this argument.
{Object} o.members Optional
Public instance members to be copied into this class's prototype.
Throws:
{Trait.TraitError}
Throws an error if the trait arguments are invalid, there is an unresolved conflict, or there is an unfullfilled trait requirement.
Returns:
{Function} Constructor for the newly created class.

Documentation generated by JsDoc Toolkit 2.0.2 on Mon Jun 22 2009 22:00:59 GMT-0700 (PDT)