I went to mean MDN JavaScript . I read the definition and do not quite understand what is happening:

JavaScript® (often simply JS) is an easy, interpretable, object-oriented language with first-class functions.

Clear. We read further, the same paragraph:

JavaScript is a prototype-oriented , multi-paradigm language with dynamic typing, which supports object-oriented, imperative and declarative (for example, functional programming) programming styles.

Now it became clear less.

If we talk about the old EcmaScript specification, then everything is clear there, the word class reserved, but not yet used. Language is really prototype-oriented. Class as a concept does not exist, but there is an object. Inheritance of objects is done through prototypes.

But here comes EcmaScript 2015, where the concept of a class already exists , classes can be inherited, etc. etc.

Turn to Wikipedia:

Prototype programming is an object-oriented programming style ...

That is, it turns out some nonsense. Why does MDN write that JS is a prototype-oriented language, and later it also indicates that it is an object-oriented language, when you could simply indicate that it is a prototype-oriented language? After all, the prototype-oriented approach is a unit of object-oriented, as far as I understood, following the logic of Wikipedia.

I ask to help to understand, after all style of the code which I write directly should depend on it. Although on the other hand, this is a multi-paradigm language. I'm confused, in short.

Closed due to the fact that it is necessary to reformulate the question so that you can give an objectively correct answer to the participants Grundy , user207618, HamSter , aleksandr barakin , cheops 29 Sep '16 at 5:26 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • So what is the question? Prototype programming is an object-oriented programming style - hence JavaScript is a prototype-oriented and object-oriented language - Grundy
  • @Grundy question is what style of code to stick with. Here will be organized full support for ES6, for example, and then what to do? How to write code? Continue to inherit through prototypes or use new features? - smellyshovel
  • OOP is a technique. No OO languages ​​exist. Simply in one OOP it is implemented easier, than in others. - ixSci
  • @smellyshovel, given. that classes are just a superstructure above the prototypes, there is no difference exactly how to write. - Grundy
  • @Grundy add-on? I did not know about this, and this fundamentally changes things. Well then, thanks for the clarification! - smellyshovel

1 answer 1

OOP programming has several programming concepts. Among them are class oriented programming and prototype oriented programming. There is a difference between these programming styles. But this difference is only a difference in the approach of creating an object - the functionality of both approaches is the same. In a class oriented programming - a class is created which strictly describes the behavior - all instances of this class will have strictly all those properties that the class has. In a prototype-oriented environment, the situation is different - here the object is created for a specific purpose and basically it has one implementation (one instance). Naturally, the prototype object can inherit other classes.

Imagine this example. Suppose the company Nissan has released the Skyline car; everyone who sees the car immediately claims that the designer of the model copied the design of the Infinity Q40 headlights, the cabin is copied one to one. In this case, people compared the prototype - that is, there is already one prototype that inherited another prototype. It looks like this code.

 var Infinity = {...}; var Skyline = Object.create(Infinity); 

That is, the prototype copied (did not inherit the behavior but copied from the created prototype) the already existing prototype.

In the case of classes, the situation is different. The class describes the concept, the behavior that will receive its copy. This can be represented by the same example. When the company introduced Skyline, everyone started talking - this is a car - it has an ear, headlights, a motor, and a cabin. Seeing Infinity, people again said - this is a car - it has an ear, headlights, a motor, a cabin. The code can be described as follows.

 class Car {...}; var Infinity = new Car(); var Skyline = new Car(); 

That is, in one case, prototypes copy prototypes in another instance inherit the behavior of classes.

True, this is just a conceptual representation of these programming approaches — at least both approaches are identical in functionality and capabilities.

You can read more here.

And the wiki is not bad to explain

And here you can pay attention to paragraph 7

  • In the case, exhaustively, with examples. Everything is as it should and how I love. Thank! - smellyshovel