Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Douglas
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
Hide 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
"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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Non anonymous functions should be declared before use.
Non anonymous functions should be declared before use
and before every statements
.
Bad Example
.. code-block:: javascript
return {
"namedFunction": function namedFunction() {
return;
if (...) {
return {
"namedFunction": function namedFunction() { ... }
};
}
// or
if (...) {
function namedFunction() { ... }
return {
"namedFunction": namedFunction
};
}
Good Example
.. code-block:: javascript
function namedFunction() { ... }
if (...) {
return {
"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 namedFunction() {
return;
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);
}
// ...
}
return {
"namedFunction": namedFunction
};
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