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

Contenido del Curso

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.

¿Todo estuvo claro?

Sección 3. Capítulo 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.

¿Todo estuvo claro?

Sección 3. Capítulo 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.

¿Todo estuvo claro?

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.

Sección 3. Capítulo 2
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt