From the course: JavaScript Essential Training

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Object methods

Object methods

- [Instructor] In addition to properties, objects can contain their own functions. These functions typically perform actions on the properties of the object. And when a function is inside an object, it is called a method. So when you hear me talk about methods, I'm referring to functions sitting inside objects. Each method is added to the object as a property. You can see here, we have a bunch of properties: Name, volume, color, and so on. And then we have two properties towards the bottom, toggle lid and new strap length that contain functions. So these are methods. There are actually two syntaxes for these methods. The one you see here is a function expression meaning we are explicitly saying inside toggle lid, there's a function that has these parameters and this is the function body. We can also do a shorthand for this by taking the function expression away and just saying toggle lid, parentheses, and then the…

Contents