Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Modifying Elements

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

How to use arrow function syntax in this course?

I am asking because up to this point my code worked but when Andrew introduced his first "this" thingy, the whole thing just didn't wanna work. It probably has something to do with the fact that arrow syntax does not have defined "this". Any ideas to work around this? I really do not want to use var xy =function () { } That is just lame now.

1 Answer

Simon Coates
Simon Coates
28,692 Points

I just did a demo that seemed to work (i'm new at JS so i hope i'm not missing anything) in which the arrow function expected the event, and used ev.target instead of this. The fragment resembled:

const deleteTask = (ev) => {
  console.log("Delete txask...");
  var listItem = ev.target.parentNode;
  var ul = listItem.parentNode;

  //Remove the parent list item from the ul
  ul.removeChild(listItem);
}

Does this help at all?