SRS Javascript Classes
This page is a guide to defining SRS classes for queries, widgets, and transformers.Guiding Principles
- Nothing should be exposed globally; everything belongs to a namespace.
- Anticipate extension.
- Expose a simple API.
Starters
- Every class is wrapped in an anonymous function to protect the global scope: (function() { ... })();
Private Members and Constants
These can be defined in the anonymous function scope for use throughout the class without exposing them publicly.... var name = value; ...
Constructors
var ClassName = function(...) { // set up member variables // run initialization logic };
(See specific constructor patterns for queries, widgets, and transformers.)
Establish Prototype
ClassName.prototype = new BaseClass(...); if BaseClass exists, otherwise ClassName.prototype = { // class methods and public static variables };
(See specific base classes for queries, widgets, and transformers.)
Extensions
ClassName.prototype.methodName = function(...) { ... };