API Docs for:
Show:

Class Class

Defined in: latest/class.js:9
Module: Class
Parent Module: JSFramework

Create a new class instance

Constructor

Class

(
  • Functions
)
Class

Defined in latest/class.js:9

Parameters:

  • Functions Object

    to add to the class

Returns:

Class: Class instance

Example:

// Creation
var Person = new Class(
{
    init: function(name)
    {
        this.name = name;
    },
    helloWorld: function()
    {
        return 'Hello';
    },
    helloWorld2: function()
    {
        return 'Hello2';
    }
});

// Instantiation
var me = new Person('Daniel');
console.log('me.name = ', me.name); // Daniel
console.log('me.helloWorld() = ', me.helloWorld()); // Hello
console.log('me.helloWorld2() = ', me.helloWorld2()); // Hello2
console.log('me instanceof Person = ', me instanceof Person); // true

Item Index

Methods

Methods

extend

(
  • proto
)
Class

Defined in latest/class.js:72

Extend the current class. Expected to be called in the context of an existing class.

Parameters:

  • proto Object

    Prototype methods of new class

Returns:

Class: Class instance

Example:

// Base class
var Person = new Class(
{
    init: function(name)
    {
        this.name = name;
    },
    helloWorld: function()
    {
        return 'Hello';
    },
    helloWorld2: function()
    {
        return 'Hello2';
    }
});

// Class that inherits from base
var Ninja = Person.extend(
{
    helloWorld2: function()
    {
        return 'Ninja helloWorld2, original = ' + this.parent();
    },
    helloWorld3: function()
    {
        return 'Ninja helloWorld3';
    }
});

var awesome2 = new Ninja('Awesome');
console.log('awesome2.name = ', awesome2.name); // Awesome
console.log('awesome2.helloWorld() = ', awesome2.helloWorld()); // Hello
console.log('awesome2.helloWorld2() = ', awesome2.helloWorld2()); // Ninja helloWorld2, original = Hello2
console.log('awesome2.helloWorld3() = ', awesome2.helloWorld3()); // Ninja helloWorld3
console.log('awesome2 instanceof Ninja = ', awesome2 instanceof Ninja); // true
console.log('awesome2 instanceof Person = ', awesome2 instanceof Person); // true

mixin

(
  • source
  • destination
)
private

Defined in latest/class.js:145

Copy functions from the source to the destination prototype. If functions already exist on the destination, a wrapper will be created that saves the old method into the .parent() method at runtime.

Parameters:

  • source Object

    Object containing functions to add

  • destination Object

    Object whose prototype will receive the new functions

wrapFn

(
  • superFn
  • fn
)
Function private

Defined in latest/class.js:121

Create a wrapper for this function. This wrapper saves the parent function into .parent (so it can be called from the overriding function) before calling the overriden function.

Parameters:

  • superFn Function

    Function on the superclass

  • fn Function

    Function on the overriding class

Returns:

Function: Function that saves superFn to .parent, runs fn, then unsets parent