Зміст курсу
Object-Oriented Programming in JavaScript
Object-Oriented Programming in JavaScript
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
.
Все було зрозуміло?
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
.
Все було зрозуміло?
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
.