+ 2
What are classes, objects, and methods?
I'm trying to learn JS, I can't really grasp what classes are. Are they just labels? I believe I know what the other two are but can someone explain them just in case?
3 Respuestas
+ 4
Think of objects as real life TVs. Every tv has dimensions, resolution, the brand name. These are attributes. Also a TV can be turned on, you can change the channels. These are the methods. The classes are the blueprints for a TV that are used in a factory. Classes initialize attributes and methods. Then you can use these classes to make objects which you can use in the program. Hope this explanation helps. I understand you, they were really confusing to me as well.
+ 4
The purpose for creating a class is to create an object from which contains all its information.
Each object you create from the class is seprate from one another.
Sometimes you might want all objects to share a particular variable in this case you would declare this variable static, this means that all objects created from this class will share this variable as it belongs to the class rather then the object.
+ 2
Imagine you have a car. This car can drive wherever you want it to. And this car has a blueprint which is saying how the car was build.
Now in this example above the car represents the object. Then we have methods. The methods describe what the car can do. In example drive around. And the class is the blueprint for the car.