Coding Style JavaScript

Location: igium / Coding Style JavaScript

General Guidelines

  • all functions are strictly defined by function f(){} and NOT by var f = function(){}
  • nested functions are ok w/o nesting level limits
  • only line-comments are allowed; NO /**/ comments!
  • named parameter objects are always named par; every function starts with a declarative block that caches the named parameters as local variables, like this:
    1
    2
    3
    4
    5
    6
    function _init(par)
    {
    var bootModuleLocator = par.bootModuleLocator;
    var bootModuleInitializer = par.bootModuleInitializer;
    var bootModuleSorter = par.bootModuleSorter;
    ...

Naming Conventions

  • local variables: camel (e.g. length, keyFieldName)
  • local constants: uppercase, underscore word delimiter (e.g. STATE_INPUT, PI)
  • function params: camel (e.g. length, keyFieldName)
  • fields: camel (e.g. modules, buildVersion)
  • methods: camel (e.g. get(), doInit())
  • enum names: capital letters, prefixed with E (e.g. ESomeName)
  • enum values: capital letters (e.g. SomeValue)
  • public: no underscore (e.g. modules, doInit)
  • public with local namespacing: no underscore, namespaces separated by dot (e.g. utility.type.isString)
  • private: underscore prefix (e.g. _copyToGlobal)
  • private with local namespacing: underscore prefix, namespaces separated by underscore (e.g. _utility_type_isString)
  • internal: doulble underscore prefix (e.g. __init) (NOTE: internal methods and fields are exposed as public by the modules, but are not intended to be used directly outside the core application infrastructure.)
  • constants: uppercase, with underscore word delimiter (e.g. PI, ENVIRONMENT_LIST_FILE_NAME)
  • named parameters param name: par
  • for functions that don't use par but use several params, the parameter holding properties that modify the function behaviour must be called options