You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
style: use dollar variables (getting links) (#1844)
As I progressed with #1584 I
felt the code examples were starting to be more and more complex. Then I
remembered that when I was young, us jQuery folks used to lean towards a
naming convention where variables holding jQuery selections were
prefixed with $. I changed the code examples in all lessons to adhere to
this as I feel it makes them more readable and less cluttered.
-----
ℹ️ The changes still use `$.map` and `$.each`, because they were made
prior to the facb3c0 commit. It's gonna
happen, but not yet.
@@ -117,24 +117,18 @@ function parseProduct(productItem) {
117
117
priceRange.price=priceRange.minPrice;
118
118
}
119
119
120
-
return { title: titleText, ...priceRange };
120
+
return { title, ...priceRange };
121
121
}
122
122
```
123
123
124
124
Now the JSON export. For better readability, let's make a small change here and set the indentation level to two spaces:
125
125
126
126
```js
127
-
asyncfunctionexportJSON(data) {
127
+
functionexportJSON(data) {
128
128
returnJSON.stringify(data, null, 2);
129
129
}
130
130
```
131
131
132
-
:::note Why asynchronous?
133
-
134
-
The `exportJSON()` function doesn't need to be `async` now, but keeping it makes future changes easier — like switching to an async JSON parser. It also stays consistent with the upcoming `exportCSV()` function, which must be asynchronous.
135
-
136
-
:::
137
-
138
132
The last function we'll add will take care of the CSV export:
139
133
140
134
```js
@@ -161,13 +155,13 @@ async function download(url) {
@@ -232,14 +226,14 @@ Several methods exist for transitioning from one page to another, but the most c
232
226
In DevTools, we can see that each product title is, in fact, also a link element. We already locate the titles, so that makes our task easier. We just need to edit the code so that it extracts not only the text of the element but also the `href` attribute. Cheerio selections support accessing attributes using the `.attr()` method:
0 commit comments