Suggestions for Code Correction in 'File Read and Write' and Update on 'Class and Object' Section
baekilda opened this issue · 2 comments
baekilda commented
Hello!
First of all, I'd like to express my gratitude for your work. This book has been instrumental in helping me quickly understand Python, and for that, I thank you!
I have a few modest suggestions regarding some parts of the book:
- In the section File Read and Write, the JavaScript example code uses the return keyword:
import fs from 'fs';
const data = fs.readFileSync('books.txt', 'utf8');
const books = data.split('\n');
const classics = ['The Story of the Stone', 'Journey to the West', 'Water Margin', 'Romance of the Three Kingdoms'];
const missingClassics = classics.filter(classic => !books.includes(classic));
if (missingClassics.length === 0) {
console.log('The file already contains the four great classical novels of China.');
return; // <- here
}
// ...
However, the return keyword must be used within a function body, while the provided code is not inside one. I believe it might be better to use if-else structure, similar to the Python example shown.
- In the Class and Object section, the first tip states, “The static keyword in the class is not native to JavaScript, but a feature provided by TypeScript.” However, considering that class static fields are now included in ES2022 and supported by most runtimes, I suggest that the part about the static keyword could be removed.
If you find these suggestions helpful, I would be happy to contribute a Pull Request to implement these changes. Please feel free to let me know.
Thank you again for your fantastic work :)