DEV Community

Discussion on: JavaScript Classes

Collapse
 
z2lai profile image
z2lai

If class is a function, why does it look like an object (class car{})? Or are you referring to the constructor function when you say class? I am new to the class syntax, sorry if it's a silly question.

Collapse
 
klaudiomilankovic profile image
Klaudio Milankovic

JavaScript class is not a Class - Kyle Simpson. Rants about it daily.

Collapse
 
mcarpenter profile image
Matthew Carpenter • Edited

I don’t believe in silly questions. Thanks for asking!

digitalocean.com/community/tutoria... - quick read, just scroll down a bit to classes are function section. Beats me typing it all as a comment.

Collapse
 
z2lai profile image
z2lai

Wow, what a great resource. So class is a function even though it looks like an object, because it has the same prototype object as a function, very weird. I just have one more question about your named class expression, let Car = class Toyota {}. Wouldn't you instantiate a new object with New Car, how would you use the "Toyota" part of the class expression?

Thread Thread
 
mcarpenter profile image
Matthew Carpenter

It’s would just give that class a name. If I were to console.log(“car.name”), it would return “Toyota”. The name is local to the classes body.

Thread Thread
 
z2lai profile image
z2lai

Ah, I think I understand all the confusing bits about class, thanks for teaching me!