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

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:

<script>
//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]");

  //delete
  deleteButton.onclick = deleteTask;

  //edit
  editButton.onclick = editTask;

  //checkbox
  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);
}
</script>

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?

Thanks!

1 Answer

Alex Flores
Alex Flores
7,864 Points

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