1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
First attempt to create coding guidelines
-----------------------------------------
1) Generally formatting style should follow Mozilla JavaScript Style Guide
(https://developer.mozilla.org/en/JavaScript_style_guide).
2) Generally I would like to follow formatting and other advice by jslint
(http://www.jslint.com/). However, I don't want to be bound by sometimes
eccentric opinions of Douglas Crockford, more I care about checking
for missing semicolons, bad spacing, etc. However, in order to make
jslint at least partially work, I need to be quite conservative in
using any non-standard constructs (Douglas strictly refused to add
any non-standard pieces of syntax, particularly let, when I emailed
him about it).
It follows that let and other non-ECMAScript construcsts shouldn't be used
or at least sparingly and only in the time of dire need.
3) Object literals should be used for pure data objects only. Instead of
var Foo.prototype = {
bar: function bar () {
console.log("We are in bar! Yuchuuu!!!");
},
baz: function baz () {
console.log("We are in baz :(");
}
};
write rather two functions separately as in
Foo.prototype.bar = function bar () {
console.log("We are in bar! Yay!!!");
};
Foo.prototype.baz = function baz () {
console.log("We are in baz :( Shooot.");
};
The latter is in my opinion more readable and works better in editors
I use (gedit, scribes, and eclipse).
4) Use plain JavaScript only. This is not multi-platform (meaning mult-browser)
script so no JavaScript libraries (e.g., jQuery, Dojo, etc.) should be
used.
On the other hand, we don't have to bound ourselves to compatibility
with anything else than platforms Add-on SDK runs on. So, instead of
hopeless non-standard constructs of jQuery, element.querySelector (with
standard CSS3 selector, which is NOT the same as what's used in
jQuery; see http://www.w3.org/TR/2009/PR-css3-selectors-20091215/) and other
advanced JavaScript functions can be used.
Any other items could be added after discussion and when a need to decide
some pressing issue happens.
|