Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we spoke about constructor functions defined on classes.
We also went through a little bit of a shortcut on assigning a property straight through the constructor
without having to add any additional function code to the constructor itself.
So in this section, we're going to do a quick review on what just happened, just to make sure that
it's really crystal clear, because this abbreviated syntax right here of initializing a property name
directly from the constructor is something that you're going to see all throughout this course in a
tremendous amount of documentation on D'Arte as well.
So let's get to it.
And I put together a quick diagram to help you understand what is going on.
And the first thing I want to remind you about is that you and I added a function to the class.
The functions name was person with a capital P because that function name was absolutely, positively
identical to the class name.
It became the constructor function for this class automatically.
Remember, a constructor function gets called automatically any time that's been defined on the class,
and it is our place to do some initialization or setup of the class instance.
Inside this constructor, we specified an argument list with exactly one argument on it, inside that
argument list, we wrote out this first name.
This means that in order for us to create a new instance of a person, we have to call a new person
and provide exactly one argument to it.
So specifically because we wrote out an argument right here that means any time we create a new instance
of a person, we have to provide one argument as well.
Now, the interesting thing about that argument that we listed there was that on the front of the argument
name we put on this dot and then we wrote out a property name or the name of a property or field that
belongs to this class because we followed that strict rules because we have this dot and then exactly
the field name right here darte decided to automatically take this argument of string, Stephen, right
here or whatever your name is in your case, and automatically assign it to the first name property
for us.
So again, specifically because we used this dot and then the exact name of the property, this got
assigned to the correct property name for us to give you a very, very quick demonstration of exactly
how that worked.
I'll flip back over to Pat over here.
Now I want to find that constructor function and I'm going to try changing first name right here to
something else, like maybe something like my first name.
Now, when I do so, you'll notice that I've got an error message down here, it says My first name
isn't a field on the inclosing class.
However, if I remove the this dot from this thing.
Then you'll notice that the error message goes away, so it's specifically the combination there of
putting this dot and the exact property name that allows us to take this shortcut in adding this property
to the class person.
So I'm now going to revert that back to this dot first name and now my code is going to work as it did
before, exactly as we expect.
OK, so again, in the section we spoke about constructor's and we spoke about this little shortcut
right here for assigning fields to a instance of a class, whenever we call the constructor function
and we call that constructor function by using the new keyword right here and then referencing the class
name.
It's now that we've got a good overview on this, let's continue in the next section where we're going
to start working on our next project that's going to heavily involve classes.
So quick break and I'll see you in just a minute.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.