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 trial

JavaScript AngularJS Basics (1.x) Services in Angular Using Services To Save and Delete Data

Srdjan Cestic
Srdjan Cestic
6,855 Points

Passing parameters to function

  this.deleteTodo = function(todo) {
    console.log("The " + todo.name + " todo is deleted!");
  };

  this.saveTodo = function(todo) {
    console.log("The " + todo.name + " todo is saved!");
  };

Can somebody explain why we set ''todo'' as parameter? Is that because we create ''todo'' object in HTML file(todo.name ; todo.completed)?

Thanks in advance

1 Answer

They todo variable is an object with different properties. We pass the entire object so that we are given access to all of its properies like todo.name rather then only passing a specific property.