Skip to content

Style Guide

Tim van der Meij edited this page Aug 2, 2014 · 32 revisions

General

Naming

  • Variables and functions - lowerCamelCase
  • Constructor-like functions - UpperCamelCase
  • Constants - ALL_UPPER_CASE_WITH_UNDERSCORES

Braces

  • Always use braces and put them on same line, even for single line control statements.
if (someVar) {
  return true;
} else {
  return null;
}

White Space

  • Space after control statements (if, else, while, for, ...)
if (someVar) {

Equalities

  • Use only strict equalities (and inequalities), e.g.
if (someVar === conditionA) {
  return true;
} else if (someVar !== conditionB) {
  return false;
}

Variables

Variables must be defined only once within a function scope. Preferably at the top of the function.

Classes

The standard way of creating classes in PDF.js is the following. Please note that by class we mean an object that is class-like. Also, note the naming of all anonymous functions.

var ClassName = (function ClassNameClosure() {
  function ClassName(...) {
    ...
  }

  ClassName.prototype = {
    functionName: function ClassName_functionName(...) {
      ...
    },

    aLongFunctionName: function ClassName_aLongFunctionName(arg1,
                                                            arg2,
                                                            ...) {
      ...
    },

    aVeryLongFunctionName: 
        function ClassName_aVeryLongFunctionName(...) {
      ...
    }
  };

  return ClassName;
})();
Clone this wiki locally