Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
40a88b02
Commit
40a88b02
authored
Feb 06, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Variable and function conventions added
parent
a70dfbc1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
10 deletions
+133
-10
docs/style_guide.rst
docs/style_guide.rst
+133
-10
No files found.
docs/style_guide.rst
View file @
40a88b02
...
@@ -214,34 +214,157 @@ Good Example
...
@@ -214,34 +214,157 @@ Good Example
"name": "Batman"
"name": "Batman"
};
};
}
}
Variable Declaration Location
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Every variables should be declared at the top of its function.
Bad Example
.. code-block:: javascript
function first() {
var a = 1, b = 2,
c, d;
// ...
}
function second() {
var a = 1, b = 2, c;
var d;
// ...
}
Good Example
.. code-block:: javascript
function third() {
var a = 1, b = 2, c, d;
// ...
}
function fourth() {
var a = 1,
b = 2,
c,
d;
// ...
}
}
Function Declaration Location
Function Declaration Location
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Non anonymous functions should be declared before use.
Non anonymous functions should be declared before use
and before every statements
.
Bad Example
Bad Example
.. code-block:: javascript
.. code-block:: javascript
if (...) {
return {
return {
"namedFunction": function namedFunction() {
"namedFunction": function namedFunction() { ... }
return
;
}
;
}
}
// or
if (...) {
function namedFunction() { ... }
return {
"namedFunction": namedFunction
};
};
}
Good Example
Good Example
.. code-block:: javascript
.. code-block:: javascript
function namedFunction() {
function namedFunction() {
... }
return;
}
if (...) {
return {
return {
"namedFunction": namedFunction
"namedFunction": namedFunction
};
};
}
Anonymous Function Location
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Execept if you want to keep your function without name, anonymous functions must
not be declared in the same place as the variables.
Bad Example
.. code-block:: javascript
function first() {
var a = 1, b = 2, func = function () {
return a;
};
// ...
}
Good Example
.. code-block:: javascript
function second() {
var a = 1, b = 2;
function func() {
return a;
};
// ...
}
You can assign a variable to an anonymous function inside **non-loop** statements.
Bad Example
.. code-block:: javascript
function third() {
var a = 1, b = 2, func;
for (...) {
b.forEach(function () { ... });
}
// ...
}
Good Example
.. code-block:: javascript
function fourth() {
var a = 1, b = 2, func;
if (...) {
func = function () { ... };
} else {
func = function () { ... };
}
// ...
}
function fifth() {
var a = [], b = [];
function func() { ... }
for (...) {
b.forEach(func);
}
// ...
}
Naming Conventions
Naming Conventions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment