Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 1.79 KB

javascript.md

File metadata and controls

21 lines (18 loc) · 1.79 KB

JavaScript guidelines

  • "classes are for designers", so don't scope with ids and classes in js. JavaScript developers should use data-* attributes, js-* prefix for classes or role attribute (go to discussion)
  • prefix jQuery objects with $ sign unless you are working with angular project (go to discussion)
  • Detect and inform about network issues, especially in SPA
  • Prefer $(this) over $(@) in CoffeeScript.
  • Try to avoid using date.js, use moment.js instead. datejs overwrites native methods and tends to break stuff.
  • Use camelCase for variable and function names. The only exception to this rule are JSON properties which are under_scored.
  • Use trailing commas in multiline object literails and multiline arrays. If you'd like to add an element you won't left your comma on the previous line. It helps to keep VCS history clean.
// Bad          // Good         // Bad            // Good
let arr = [     let arr = [     let obj = {       let obj = {
  'foo',          'foo',          foo: 'foz',       foo: 'foz',
  'bar'           'bar',          bar: 'baz'        bar: 'baz',
];              ];              };                };

JavaScript on Rails