From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Object methods and 'this' keyword - JavaScript Tutorial
From the course: Coding for Visual Learners: Learning JavaScript from Scratch
Object methods and 'this' keyword
- [Speaker] We can also define functions as values for keys on objects. So here I can create a new key called paintItBlack, which will have a function as a value. And if you use a function as a key value, then the resulting properties is referred to as a method. If any of the keys have any other value, then they are called properties on an object. But if they have a function as a value then that property is referred to as a method. So methods are functions, and inside the methods I can have a function that will do anything. And one of the cool things is that I can actually refer to the other properties on the object itself. So if I wanted to console log the value for the property black inside this paintItBlack function, I can refer to it by saying black. Not really though, because then JavaScript thinks that we are referring to a variable called black that exists inside the scope, which is not true. Black is a property name…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.