All language subtitles for 23. ES6 Classes Summary

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

So as we reach the end of this section, 2

2

let's quickly review all the terminology around classes 3

3

because there is so much different stuff going on. 4

4

So a lot of different features that you can use. 5

5

And since classes are probably the way 6

6

you're gonna implement OOP by yourself, 7

7

it's always good to have a nice overview of everything 8

8

that we can do with them. 9

9

So here we have a huge class, 10

10

which essentially contains all the features 11

11

that we studied over the last couple of lectures. 12

12

So this is how we define a class. 13

13

And in this case, it is actually a child class. 14

14

So student is a child class of the parent class person 15

15

and that is because here we are using the extends keyboard 16

16

to set up the inheritance between these two classes. 17

17

And remember that the extends keyword 18

18

will also automatically set up the prototype chain for us. 19

19

So we don't have to do anything manually. 20

20

Next up, this is how we define a public field. 21

21

So this is what we did in a very recent lecture. 22

22

And so remember that a public field is very similar 23

23

to just a property that we defined in a constructor. 24

24

So it is available on every created object. 25

25

So on every instance created by this class. 26

26

Then of course, we also have private fields 27

27

and they are almost the same as public fields, 28

28

but they are not accessible outside of the class. 29

29

And so therefore this is perfect 30

30

for implementing data privacy and encapsulation. 31

31

We also have static public fields. 32

32

And so these are fields or like properties 33

33

that are available only on the class. 34

34

And I didn't show them to you in the code. 35

35

So in one of the lectures, 36

36

but this is how we can implement them. 37

37

So just like static methods, 38

38

we use the static keyword to make any field static as well. 39

39

Then here, this is the constructor method 40

40

and it is automatically called by the new operator 41

41

whenever we create a new instance of the class. 42

42

So basically a new object. 43

43

And this constructor method is mandatory 44

44

in any regular class, but it might be omitted 45

45

in a child class if we want it to have the exact same number 46

46

and the exact same name of parameters. 47

47

Then inside of the constructor there is the call 48

48

to the parent class and so that is the superclass. 49

49

And this of course is only necessary 50

50

whenever we are writing a child class. 51

51

So when we're using the extent keyword. 52

52

And remember that this one needs to happen 53

53

before we access the disc keyword in the constructor. 54

54

Then here we have an instance property. 55

55

And so just like public fields, 56

56

the property is also available on each created object. 57

57

But the difference between this one and the public field 58

58

is that we set these instance properties 59

59

based on input data of the constructor. 60

60

So basically these properties are more personalized 61

61

and unique for each object while the fields are usually 62

62

for something that is common to all the objects. 63

63

For example, here at the university for all of the students 64

64

is the University of Lisbon. 65

65

And so that is not unique to each object, okay. 66

66

Then here we are redefining a private field. 67

67

And so this is what we did with the pin 68

68

in the bank account example, right? 69

69

So this private field should be unique for each student. 70

70

And so we created the private fields out there 71

71

without any value. 72

72

And then here we are simply redefining it to the value 73

73

that is coming into the constructor. 74

74

Then here, as we already know, is a normal public method. 75

75

Here, we are referencing a private field 76

76

and also a private method. 77

77

And so about the private methods, 78

78

this is how they look like. 79

79

But as I mentioned, 80

80

they will probably not yet work in your browser. 81

81

At least if you're watching this close 82

82

to the recording date of this course. 83

83

So as an alternative, you can fake private methods 84

84

by using the underscore convention instead of the hash. 85

85

Next up, this is what a getter method looks like. 86

86

And remember that a getter method is basically 87

87

so that we can get a value out of an object 88

88

by simply writing a property instead of writing a method. 89

89

So in this case, we could simply write student.testscore 90

90

and that would then run this getter method 91

91

and the same for the setter method. 92

92

So in this case, we can simply define the test score 93

93

by setting it to some value 94

94

instead of calling a test score method. 95

95

And keep in mind that if you have a setter 96

96

for a property that is already defined in the constructor, 97

97

then you need to create basically a new property 98

98

with the underscore in front of it. 99

99

So again, that is kind of a convention 100

100

that you should use in this case. 101

101

And then in the getter with the same name, 102

102

you also need to then return that new property. 103

103

So we did that in one of the lectures, 104

104

when we did a name validation for the name 105

105

that was passed into the constructor. 106

106

Remember that? 107

107

Next, this is how your write static methods 108

108

and a static method is available only on the class. 109

109

So it cannot access the instance properties nor the methods, 110

110

but only the static ones. 111

111

So for example, that static public fields 112

112

that we defined there in the top 113

113

will of course be accessible in the static method. 114

114

And usually we use these static methods 115

115

as helper methods for the class. 116

116

Finally, this is how you then create a new object 117

117

using the new operator. 118

118

And so this should be nothing new at this point for you. 119

119

Now, here's just a couple of things 120

120

that we need to remember about classes 121

121

and that I actually already mentioned before as well. 122

122

So keep in mind that classes are really just 123

123

syntactic sugar over constructor functions. 124

124

Also classes are not hoisted, they are first class citizens 125

125

and the class body is always executed in strict mode. 126

126

Okay, and there you'll have it. 127

127

This is an overview and also a summary 128

128

of the entire syntax of classes in JavaScript.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.