Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
Léo-Paul Géneau
gitlab-ce
Commits
c7049ed0
Commit
c7049ed0
authored
Apr 20, 2017
by
Filipa Lacerda
Committed by
Phil Hughes
Apr 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds documentation entry: Don't user forEach, aim for code without side effects
parent
9bef6ce6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
doc/development/fe_guide/style_guide_js.md
doc/development/fe_guide/style_guide_js.md
+17
-0
No files found.
doc/development/fe_guide/style_guide_js.md
View file @
c7049ed0
...
...
@@ -168,6 +168,23 @@ See [our current .eslintrc][eslintrc] for specific rules and patterns.
-
Avoid constructors with side-effects
-
Prefer
`.map`
,
`.reduce`
or
`.filter`
over
`.forEach`
A forEach will cause side effects, it will be mutating the array being iterated. Prefer using
`.map`
,
`.reduce`
or
`.filter`
```
javascript
const
users
=
[
{
name
:
'
Foo
'
},
{
name
:
'
Bar
'
}
];
// bad
users
.
forEach
((
user
,
index
)
=>
{
user
.
id
=
index
;
});
// good
const
usersWithId
=
users
.
map
((
user
,
index
)
=>
{
return
Object
.
assign
({},
user
,
{
id
:
index
});
});
```
#### Parse Strings into Numbers
-
`parseInt()`
is preferable over
`Number()`
or
`+`
...
...
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