Skip to content
cederberg edited this page Oct 12, 2010 · 1 revision

MochiKit's coding conventions largely follow that of Python's PEP 8 and PEP 7 (in that order of precedence), but there are a number of JavaScript-specific points:

  • NEVER modify a built-in object or its prototype (e.g. don't do this: Object.prototype.foo = REALLY_BAD!). Prefer functions instead.
  • Use the typeof operator as if it were a function: typeof(x) instead of typeof x
  • Use parentheses for the arguments when using a constructor: new Error("foo") instead of new Error, foo
  • Always use fully qualified references to all other functions, and don't use the symbolic convenience aliases:
    • use MochiKit.DOM.getElement(x) instead of $(x)
    • use MochiKit.Logging.logFatal(x) instead of logFatal(x)
    • use MochiKit.ThisModule.exportedFunction(x) instead of exportedFunction(x)
  • Always use a newline after an opening brace, as if it were a colon in Python
  • Use PEP 8 spacing whenever applicable, such as spaces between operators: i = 0 instead of i=0, "foo" + sig + "bar" instead of "foo"+sig+"bar", etc.
  • Never use more than one space except for the indent. In other words, don't try and make code line up as if it were a spreadsheet.
Clone this wiki locally