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:
.. _`PEP 7`: http://www.python.org/peps/pep-0007.html
.. _`PEP 8`: http://www.python.org/peps/pep-0008.html
- 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)``
etc.
The same goes for intramodule calls:
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.