The difference is that in Java, C++, python, php and other languages that support OOP you usually have two different language elements - one is Class
which serves as a metadata and then we create new objects based on the class definitions; object
this way is the second element of the language.
In JavaScript there is no Class
element, there is only object
. And we can create an object and then use it as a prototype to create other objects, for example:
var animal = {
"name": "Bim",
"age": 5
};
// now we can use the animal object iself, for example pass it to some function
// that shows object name
function showName(obj) {
alert(obj.name);
}
showName(animal);
// but we also can use it as a prototype to create new objects
var dog = Object.create(animal);
dog.bark = function() {
alert(this.name + ": bark! bark!");
}
dog.name = 'Pluto';
dog.bark();
There are ways to emulate the OOP with classes as it works in other languages and that is what you are probably referring to in act in the same way, but only with a weird and tricky syntax
.
Actually is not necessary to have classes and it depends on your habits and application design. It is possible to work with just objects especially if you prefer composition to inheritance.