Changes between Initial Version and Version 1 of WebInspectorCodingStyleGuide


Ignore:
Timestamp:
Nov 6, 2013 9:56:07 AM (9 years ago)
Author:
Alexandru Chiculita
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WebInspectorCodingStyleGuide

    v1 v1  
     1* No trailing whitespace
     2* Indent with 4 spaces
     3* The opening bracket "{" after a named function goes on the next line. Anywhere else, the opening bracket "{" stays on the same line.
     4* Style for JavaScript Object Literals is: {key1: value1, key2: value2}.
     5* Inline anonymous functions, especially if they don't need a .bind(). Example:
     6{{{
     7    this.requestRootDOMNode(function(rootNode) {
     8        ...
     9    });
     10}}}
     11* Avoid using the "on" prefix where possible. The "_onFoo" methods can just be "_foo".
     12* New class names should use the name of the base class as a sufix.
     13* Add new lines before and after different tasks performed in the same function.
     14* Consider using Map structure instead of Object.
     15* Consider using rgb() over hex colors in CSS
     16* Firewall the protocol inside the Manager classes. JSON objects received from the protocol are called "payload" in the code. The payload is usually deconstructed at the Managers level and passes down as smart objects inheriting from WebInspector.Object.
     17
     18The new JS object types should have the following format:
     19
     20{{{
     21WebInspector.NewObjectType = function()
     22{
     23    WebInspector.Object.call(this);
     24    this._propertyName = ...;
     25}
     26
     27WebInspector.NewObjectType.Event = {
     28    PropertyWasChanged: "new-object-type-property-was-changed"
     29};
     30
     31WebInspector.NewObjectType.prototype = {
     32   
     33    constructor: WebInspector.NewObjectType,
     34    __proto__: WebInspector.Object.prototype,
     35
     36    // Public
     37
     38    get propertyName()
     39    {
     40        return this._propertyName;
     41    },
     42
     43    set propertyName(value)
     44    {
     45        this._propertyName = value;
     46        this.dispatchEventToListeners(WebInspector.NewObjectType.Event.PropertyWasChanged);
     47    },
     48
     49    publicMethod: function()
     50    {
     51        /* public methods called outside the class */
     52    }
     53
     54    // Private
     55
     56    _privateMethod: function()
     57    {
     58        /* private methods are underscore prefixed */
     59    }
     60};
     61}}}