Fields vs. Method Arguments

  1. class fields > constantly passing data as arguments > read data from DOM elements [code]
  2. DON’T use fields: Two ‘threads’ using the object at the same time will confuse each other (e.g. ‘static variable’).  [source] SOLUTION: Create an abstract class with a method to create only one instance whenever needed.

Style Guide 

(google, idiomatic)

  1. Function:
    1. don’t declare function within blocks [code]
  2. Property:
    1. initialize properties only in the constructor for better performance [code]
    2. don’t declare implicit variable in block scope [code]
    3. access prefer object.property over object[“property”] [code]
    4. delete prefer object.property = null over delete object.property for better performance [code]
    5. replace array with object [source]
  3. Format:
    1. prefer ‘ over ” [source]
    2. use JSDoc for comments [source]
Advertisements