BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
9e4908af
Commit
9e4908af
authored
Apr 20, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'doc-js-side-effetcs' into 'master'
Adds documentation entry: Don't user forEach, aim for code without side effects See merge request !10811
parents
9bef6ce6
c7049ed0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
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 @
9e4908af
...
...
@@ -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