Skip to content

Commit 85fbe7c

Browse files
authored
Merge pull request #6885 from meezwhite/docs/issue-6797
docs(styleguide): add section on chaining
2 parents e947f2e + a7e3600 commit 85fbe7c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

contributor_docs/documentation_style_guide.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Our community is large and diverse. Many people learn to code using p5.js, and a
3535
- [Arrays](#arrays)
3636
- [Functions](#functions)
3737
- [Arrow Functions](#arrow-functions)
38+
- [Chaining](#chaining)
3839
- [Classes](#classes)
3940
- [Assets](#assets)
4041

@@ -1041,6 +1042,30 @@ function processImage(img) {
10411042
// Good.
10421043
[1, 2, 3].map((number) => number * number);
10431044
```
1045+
**[⬆ back to top](#table-of-contents)**
1046+
1047+
## Chaining
1048+
1049+
* Use individual function calls instead of function chaining.
1050+
1051+
> Why? To accommodate users who may not be familiar with the concept of function chaining.
1052+
1053+
```javascript
1054+
// Bad.
1055+
fill(0)
1056+
.strokeWeight(6)
1057+
.textSize(20);
1058+
1059+
// Bad.
1060+
fill(0).strokeWeight(6).textSize(20);
1061+
1062+
// Good.
1063+
fill(0);
1064+
strokeWeight(6);
1065+
textSize(20);
1066+
```
1067+
1068+
**[⬆ back to top](#table-of-contents)**
10441069

10451070
## Classes
10461071

0 commit comments

Comments
 (0)