Breaking up method chains across multiple lines makes them more legible for humans. In this video, learn how to format method chains across multiple lines to make them easier to read.
- [Instructor] Chaining methods together enables you … to write compact code that accomplishes a task … without unnecessary reassignment, … however, the trade off for that compactness … can be dense code that's hard to read. … To make long method chains more legible, … it's useful to break them up onto multiple lines … with a dot preceding a method name starting a new line, … combined with indenting the methods below … the first line of the statement. … This format makes it easy to understand the sequence … of modifications being applied, … as well as where the chain begins and ends. … ESLint includes the newline-per-chained-call rule … which flags errors in your code … if your methods aren't on their own lines. … In my app that identifies points of interest … based on a user's location, I'm building a fetch request … to the US Park's Service API to get information … on national parks. … Notice that I already have one error here, … and that's just because I have a really long line … that includes a couple of chain methods. …
- Using modern deployment tools
- Working with ESLint
- Creating easy-to-read comments
- Using commas consistently
- Standardizing line length in your code
- Using a consistent format for blocks
- Choosing and implementing a standard indent
Skill Level Intermediate
Workflow Tools for Web Developerswith Christina Truong1h 13m Intermediate
Set up your environment3m 22s
1. Why Best Practices?
2. Creating Comments
3. Using Punctuation
4. Using Spacing
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.