Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Static Functions | Static
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

Static Functions

Methods also can be static. Let’s create compare() method with two parameters: studentA and studentB. This function will output which student has a higher GPA.

To call this method, you also have to use the name of the class, not the object:

Inside the static method, you can refer only to static class attributes, using this keyword, because non-static attributes are unique for each object, so for the whole class, they are undefined.

Note that in function compare() you refer to the non-static objects attributes studentA and studentB, but to the static class attributes Student.

Everything was clear?

Section 3. Chapter 2
toggle bottom row

Static Functions

Methods also can be static. Let’s create compare() method with two parameters: studentA and studentB. This function will output which student has a higher GPA.

To call this method, you also have to use the name of the class, not the object:

Inside the static method, you can refer only to static class attributes, using this keyword, because non-static attributes are unique for each object, so for the whole class, they are undefined.

Note that in function compare() you refer to the non-static objects attributes studentA and studentB, but to the static class attributes Student.

Everything was clear?

Section 3. Chapter 2
toggle bottom row

Static Functions

Methods also can be static. Let’s create compare() method with two parameters: studentA and studentB. This function will output which student has a higher GPA.

To call this method, you also have to use the name of the class, not the object:

Inside the static method, you can refer only to static class attributes, using this keyword, because non-static attributes are unique for each object, so for the whole class, they are undefined.

Note that in function compare() you refer to the non-static objects attributes studentA and studentB, but to the static class attributes Student.

Everything was clear?

Methods also can be static. Let’s create compare() method with two parameters: studentA and studentB. This function will output which student has a higher GPA.

To call this method, you also have to use the name of the class, not the object:

Inside the static method, you can refer only to static class attributes, using this keyword, because non-static attributes are unique for each object, so for the whole class, they are undefined.

Note that in function compare() you refer to the non-static objects attributes studentA and studentB, but to the static class attributes Student.

Section 3. Chapter 2
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