hello and welcome to texted tutorials
today we are going to learn about
Colossus we are coming to a turning
point in this series about object or de
jóska usually in any programming any
object or in caproni language when you
start you learn about classes but
javascript is very special so before we
go deep into the classes let's
understand what classes means to
JavaScript
I'm sure we all have opinions on whether
we do need classes or not but they are
here and they are here to stay and they
are being used not everywhere but they
are being used so it is important to
learn about them JavaScript now has a
class key keyword since
es 2015 release which is great so now
all your Java programmers if you are
you'll feel like home
I believe objective of the people who
edit classes to JavaScript to make you
feel home however I think Java
programmers are going to be even more
confused because classes are not what
they think they are in JavaScript it's
like my friend who wants his kids to eat
more vegetables so he uses tofu and
serve cheese and spinach instead of
pepperoni even if he hides it in the
middle layer of the pizza the first bite
that kid takes he would recognize it
that this is not a pizza and Java
programmer is gonna feel the same way as
soon as they start using it they would
figure out that JavaScript classes are
nothing but function constructors with
prototype methods so without further
delay let's start coding and let's
define our first class since we used the
car example throughout this series let's
define our first class called car and
the syntax is pretty simple
you would
type the class keyword and then the name
of the class which will be car and
within the curly brackets it would be
the body of the class remember there is
no semicolon at the end of the class and
inside the body let's try the
constructor the constructor would
initialize the the properties so you
would say constructor and it would be
you pass the parameter color and inside
you would just simply say this start
color equal to color similar to the
function constructor so we have defined
our first class called car and it has a
constructor which sets the color
property that's what it does now before
we create our first object using this
class let's understand what this class
is so we can look at it in a console log
and if I execute this I would see class
car and if I expand it I would have a
prototype hmm and inside I have a
constructor which is car so it is still
using the prototype inside so this
pretty much looks like a regular
function constructor where the
constructor is but instead of function
it says class car however if I look at
the type of car between showmen show me
what is the type of car since JavaScript
doesn't have an extra type called class
what should it be so if I run it it says
function so type of class is function
its function which means classes are
nothing but functions in JavaScript it
just you know using the special keyword
so it looks nice however internally
it's using functions and I can create
the same class using a function
constructor and we can compare how it
creates objects so what I would do is to
do that I would have to create an
immediately booked a function expression
if you don't know what it is I have a
tutorial on it so you can look at it so
it would be something like this
and it would be basically immediately
invoked function expression which unites
like this and you would pass a callback
function that gets executed as soon as
you call this
so we be something like this function
and inside it would return inside it
would return it would create it would
have this inside it would have this car
function which which would be nothing
but a function constructor and it would
just set the property color just like
function constructor do this dot color
equal to color and you would have to
return this scarf well you can just call
it something like this so it does not
get confused with this car here so if I
look at this console.log car so you
would see car and it would have a
prototype which would have a constructor
NSS function if I put both side by side
here I have a class car and here I have
a function car which is a constructor
and as you can see here it's called
class here it's called function and this
one has a prototype this one also has
prototype and as a constructor inside
which says class car this has a
constructor inside which is a function
car so this pretty much is the same
thing inside here since there is
actually no such thing as class
inside JavaScript it just simulates as
the same behavior using the class
keyword now let's add our first method
in this class called car when I have a
method called Drive and if you're used
to so much like object jason object
where you would use commas like this do
not do it this is a class so we don't
have to put the commas and inside this
drive method all I'm gonna do it just
say console.log and I would just say
driving simple right
now if I look at the car class again it
would say class car and it would inside
this prototype I would have the drive
method so the drive is actually nothing
but a prototype matter and I can submit
it the same thing using the function
constructor all I have to do here is car
dot prototype dot drive equal to
function and it would just say
console.log driving and now if I look
this car constructor I would get the
prototype and it would have a try matter
so if I look at the comparison
side-by-side they both have a prototype
which with constructor and drive method
somehow in class the constructor shows
up first and then drive and here the
drive shows the first and construct I
don't know what as you can see there's
not much difference now let's create our
first object and creating object is very
simple you would just say let red car so
this is object we're gonna create and
you still have to use a new keyword car
and inside you will pass the color
parameter so here I would say since it's
a red car and I would pass red all right
so now if I look at the red car
I would see car it has a color red and
it would have proto underscore
underscore proto underscore underscore
and it's creator and inside you would
have two things drive and it's
constructed so now you know what classes
are in JavaScript let's look at
subclasses in next tutorial and I hope
you learn something from it and if you
did please like subscribe and provide a
constructive comment and the example I
have showed here I will put it on my
Texan site and I'll provide a link at
the end of the tutorial and also if you
can translate this video to your native
language if you are if your native
language is different than English I
would really appreciate it so I can
provide closed captioning in different
languages
I would try but I don't know many
languages and it's best if my audience
does it so I can have wide variety of
closed captioning available so more
people can learn from my videos and in
the description hour I would provide a
link so you can go there and and you can
open the link and you can translate from
there and let me know once you translate
so I'll give you credit for your work
and thank you in advance