node-webodf
Version:
WebODF - JavaScript Document Engine http://webodf.org/
37 lines (18 loc) • 2.18 kB
Markdown
## Coding Standards
### Rules for declaring types in JavaScript code
1. For the types ```string```, ```number```, ```boolean``` and ```function```, the ```!``` shall be written explicitly.
__Example__: ```/**@type {!Array.
}*/``` to type an object as array of functions which require a ```string``` value, not ```null``` or ```undefined``` as argument and always return a ```boolean``` value, never ```null``` or ```undefined```
__Rationale__: While for ```string```, ```number``` and ```boolean``` types it is rather weird to have the ```null``` value, it is still better to write the default explicitely, to prevent errors like seen in Closure Compiler's own externs declarations and for consistenty with the rules 2) to 4).
(Agreed on in ["coding rules for types" ml thread])
2. For the types ```Object```, ```Array``` and ```Function```, the ```?``` shall be written explicitly.
__Example__: ```/**@return {?Node}*/``` to define that a method returns either an object of type ```Node``` or value ```null```
__Rationale__: Null pointers can be a problem. The compiler checks the nullness when passing an object but not when accessing a member. Keeping awareness of nullness high is good.
(Agreed on in ["coding rules for types" ml thread])
3. Objects will always explicitly have ```string``` as the key. So each Object in a type definition starts with ```Object.