Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Keyword 'this' | Classes & Objects
Object-Oriented Programming in JavaScript
course content

Course Content

Object-Oriented Programming in JavaScript

Object-Oriented Programming in JavaScript

1. Classes & Objects
2. Encapsulation
3. Static
4. Inheritance

Keyword 'this'

You can refer to the attributes not only outside the class but inside, too, for example, inside methods. To do that, use this keyword. this is like a name of object, but it means the current object, i. e. it refers to the global object.

Let's change current age of the student each time we call happyBirthday() function, and print it:

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Everything was clear?

Section 1. Chapter 5
toggle bottom row

Keyword 'this'

You can refer to the attributes not only outside the class but inside, too, for example, inside methods. To do that, use this keyword. this is like a name of object, but it means the current object, i. e. it refers to the global object.

Let's change current age of the student each time we call happyBirthday() function, and print it:

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Everything was clear?

Section 1. Chapter 5
toggle bottom row

Keyword 'this'

You can refer to the attributes not only outside the class but inside, too, for example, inside methods. To do that, use this keyword. this is like a name of object, but it means the current object, i. e. it refers to the global object.

Let's change current age of the student each time we call happyBirthday() function, and print it:

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Everything was clear?

You can refer to the attributes not only outside the class but inside, too, for example, inside methods. To do that, use this keyword. this is like a name of object, but it means the current object, i. e. it refers to the global object.

Let's change current age of the student each time we call happyBirthday() function, and print it:

Task

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

Section 1. Chapter 5
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt