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!

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 trial


Alex Flores
Alex Flores
7,864 Points

JavaScript Data Structure / Interpreter question?

I'm just curious if someone could tell me what the interpreter is doing in the following code and/or is there a name for this technique. The code below is basically a binding event:

//Create binding events so tasks can move freely
var bindTaskEvent = function(taskListItem, checkBoxEventHandler) {
  var deleteButton = taskListItem.querySelector("button.delete");
  var editButton = taskListItem.querySelector("button.edit");
  var checkBox = taskListItem.querySelector("input[type=checkbox]");

  deleteButton.onclick = deleteTask;

  editButton.onclick = editTask;

  checkBox.onchange = checkBoxEventHandler;

addButton.onclick = addTask;

for(i = 0; i < incompletedTasks.children.length; i++){
  bindTaskEvent(incompletedTasks.children[i], taskComplete);

for(i = 0; i < completedTasks.children.length; i++){
  bindTaskEvent(completedTasks.children[i], taskIncomplete);

I understand how it works for the most part, but I'm not entirely sure if the interpreter runs the code and stores an instance of it (if so where?) or it just doesn't run it and once someone clicks on the button, then the interpreter runs to that line of code?


1 Answer

Alex Flores
Alex Flores
7,864 Points

I think I got it. It's called an event listener?