Skip to content

X:style

haehn edited this page May 7, 2012 · 10 revisions

XTK coding style draft

Table of Contents

Class Design

  • if possible, always inherit from X.base - this enables the event system
  • each class has a className attribute (for duck typing and down casting)
  /**
   * @inheritDoc
   * @const
   */
  this['className'] = 'renderer';
  • export symbols (only methods/functions) to avoid optimization by the compiler but only as little as required since it blows up the library size

Class variables / Properties

  • Only public or protected properties
  • Public properties replace simple getters like this (which avoids optimization by the compiler):
 this['container'] = _container;
  • Protected properties (will be renamed during optimization)
 this.objects = new X.array();

Local variables

  • always start with a underscore (_)

Loops

  • decrementing while loop is faster than for
  • Fast Duff's Device is the fastest but takes more lines of code
Clone this wiki locally