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

Зміст курсу

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.

Все було зрозуміло?

Секція 3. Розділ 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.

Все було зрозуміло?

Секція 3. Розділ 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.

Все було зрозуміло?

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.

Секція 3. Розділ 2
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt