From a140ab434126c3767a3228b7a20173bed3a131f0 Mon Sep 17 00:00:00 2001 From: meezwhite Date: Mon, 18 Mar 2024 13:16:07 +0100 Subject: [PATCH 1/2] docs(styleguide): add section on chaining Co-authored-by: Nick McIntyre --- contributor_docs/documentation_style_guide.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contributor_docs/documentation_style_guide.md b/contributor_docs/documentation_style_guide.md index 76d52c12d1..5bb83d6ae6 100644 --- a/contributor_docs/documentation_style_guide.md +++ b/contributor_docs/documentation_style_guide.md @@ -35,6 +35,7 @@ Our community is large and diverse. Many people learn to code using p5.js, and a - [Arrays](#arrays) - [Functions](#functions) - [Arrow Functions](#arrow-functions) +- [Chaining](#chaining) - [Classes](#classes) - [Assets](#assets) @@ -1041,6 +1042,30 @@ function processImage(img) { // Good. [1, 2, 3].map((number) => number * number); ``` +**[⬆ back to top](#table-of-contents)** + +## Chaining + +* Use individual function calls instead of chaining. + +> Why? It's easier to read and understand, especially for beginners who are unfamiliar with function chaining. + +```javascript +// Bad. +fill(0) + .strokeWeight(6) + .textSize(20); + +// Bad. +fill(0).strokeWeight(6).textSize(20); + +// Good. +fill(0); +strokeWeight(6); +textSize(20); +``` + +**[⬆ back to top](#table-of-contents)** ## Classes From a7e36005aaa9a908fa4d409d12338710feecae3f Mon Sep 17 00:00:00 2001 From: meezwhite Date: Mon, 18 Mar 2024 16:29:25 +0100 Subject: [PATCH 2/2] docs(styleguide): improve wording on chaining --- contributor_docs/documentation_style_guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contributor_docs/documentation_style_guide.md b/contributor_docs/documentation_style_guide.md index 5bb83d6ae6..973308a9a4 100644 --- a/contributor_docs/documentation_style_guide.md +++ b/contributor_docs/documentation_style_guide.md @@ -1046,9 +1046,9 @@ function processImage(img) { ## Chaining -* Use individual function calls instead of chaining. +* Use individual function calls instead of function chaining. -> Why? It's easier to read and understand, especially for beginners who are unfamiliar with function chaining. +> Why? To accommodate users who may not be familiar with the concept of function chaining. ```javascript // Bad.