Tour API Demos Download Tests
Aperture version 1.0
Generated by: JsDoc Toolkit 2.4.0

Class aperture.Class

Class is the root of all extended Aperture classes, providing simple, robust patterns for classical extensibility. An example is provided below showing how to extend a new class.

Class Summary
Constructor Attributes Constructor Name and Description
This constructor is abstract and not intended to be invoked.

Method Summary

Class Detail

This constructor is abstract and not intended to be invoked. The examples below demonstrate how to extend a new class from a base class, and how to add a view constructor to a base class.

Method Detail

  • <static> aperture.Class.addView(viewName, properties)
    Declares a class method which, when called on a runtime instance of this class, instantiates a 'view' of the object using JavaScript's prototype based inheritance, extending its methods and properties with those provided in the properties parameter. View methods may access a reference to the base object using the _base member variable. Views use powerful and efficient features of JavaScript, however however unlike in the case of Class extension, some allowances must be made in the design of base classes to support the derivation of views for correct behavior. The following provides an example:
    var ValueClass = aperture.Class.extend( 'ValueClass', {
        // constructor
        init : function( value ) {
            // create a common object for all shared variables.
            this.common = { value : value };
        // sets the value in the object, even if called from a view.
        setValue : function( value ) {
            // use the common object to set the value for all,
            // as opposed to overriding it locally.
            this.common.value = value;
        // returns the value.
        getValue : function( value ) {
            return this.common.value;
    // declare a new view constructor
    ValueClass.addView( 'absolute', {
       // optional view constructor, invoked by a call to absolute().
       init : function( ) {
           // Because of JavaScript prototype inheritance, note that
           // any this.* property value we set will be an override
           // in this view until deleted.
       // overrides a parent class method.
       getValue : function( ) {
           // call same getValue method defined in base object.
           // we can choose (but here do not) what this.* should resolve
           // to in the base method call by using function apply() or call().
           return Math.abs( this._base.getValue() );
    // derive a view of an existing object
    var myObj = new MyClass( -2 ),
        myAbsView = myObj.absolute();
    // value now depends on whether you call the base or view
    console.log( myObj.getValue() );     // '-2'
    console.log( myAbsView.getValue() ); //  '2'
    {String} viewName
    the name of the view method to create, reflective of the type being declared
    {Object} properties
    a hash of functions to add to (or replace on) the base object when the view is created.
    this (allows chaining)
  • <static> aperture.Class.extend(className, properties)
    Extends a new class from this class, with any new or overridden properties and an optional init constructor defined in the properties parameter. Any methods which are overridden may call this._super() from within the context of the overridden function to invoke the parent classes implementation. A className is supplied as the first parameter for typeOf() evaluation, which may be omitted for anonymous classes. Extend may be called on any previously extended Class object. For example:
    var MyClass = MyBaseClass.extend( 'MyClass', {
       // optionally define constructor
       init : function( exampleArg ) {
           // optionally call super class constructor
           this._super( exampleArg );
       // example method override
       exampleMethod : function() {
           // optionally call same method in parent.
    // example instantiation
    var myObj = new MyClass( exampleArg );
    {String} className Optional
    an optional type specifier which may be omitted for anonymous classes.
    {Object} properties
    a hash of methods and members to extend the class with.
    a new class constructor.
  • {Boolean|String} typeOf(name)
    Provides a method of checking class and view type inheritance, or simply returning the type name. A fully scoped name may be provided, or a regular expression for matching. Alternatively the class or view constructor may be passed in.
    var range = new aperture.Scalar('Percent Change GDP').symmetric();
    // check using regular expressions
    console.log( range.typeOf(/scalar/i) );         // 'true'
    console.log( range.typeOf(/symmetric/) );       // 'true'
    // check using names
    console.log( range.typeOf('aperture.Scalar') );  // 'true'
    console.log( range.typeOf('aperture.Range') );   // 'true'
    console.log( range.typeOf('aperture.Ordinal') ); // 'false'
    // check using prototypes. also 'true':
    console.log( range.typeOf( aperture.Scalar ) );
    console.log( range.typeOf( aperture.Scalar.prototype.symmetric ) );
    {String|RegExp|Constructor} name Optional
    the name, regular expression, or constructor of the view or class type to check against, if checking inheritance.
    {Boolean|String} if a name argument is provided for checking inheritance, true or false indicating whether the object is an instance of the type specified, else the name of this type.