Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMichael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsMy chargeFines method
My chargeFines method is this:
chargeFines = () => {
this.patrons.filter(patron => patron.out)
.forEach(patron => {
const today = new Date();
if (today > patron.currentBook.dueDate) {
const day = today.getDate();
const due = patron.currentBook.dueDate.getDate();
const daysLate = day - due;
patron.balance = daysLate * this.dailyFine;
}
});
}
I think it is actually a more elegant solution than Ashley's, but could someone with more experience critique it and tell me if I am on the right track? Thanks!
1 Answer
Steven Parker
231,261 PointsDid you test this? I'm wondering because arrow functions do not define a "this" like conventional functions do.
Michael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsMichael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsAfter I posted this I did end up testing it and it does produce the desired behaviour. However I am now wondering if there is a more efficient way of writing the function. Steven do you think you could point me to a resource you know of explaining
this
in the context of arrow functions?Steven Parker
231,261 PointsSteven Parker
231,261 PointsMDN is my "go to" reference for all things front-end. Here's the page on Arrow Functions.
Look for the highlighted section titled "No separate this".
But also note that MDN advises "Arrow function expressions are ill suited as methods..."
Michael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsMichael Cook
Full Stack JavaScript Techdegree Graduate 28,975 PointsThank you very much.