javascript - prototype based vs. class based inheritance -
In javascript, each object is an instance and class at the same time. To inherit, you can use any object instance as a prototype.
In Python, C ++, etc. There are classes and examples in the form of different concepts. In order to inherit, you have to use the base class to create a new class, which can then be used to create derivative instances.
Why does javascript run in this direction (prototype-based object orientation)? What are the advantages (and disadvantages) of prototype-based oo in relation to traditional, class based oo? There are issues of about one hundred vocabulary, which are mostly made around anyone (not you) your idea is the best. Are trying to make like.
All object-oriented languages should be able to deal with many concepts:
- Encapsulation of data with the associated operations of data, which is the form of data members and member functions In the form of data and methods, in addition to other things, or among other things. Heritage is the ability to say that these objects are contrary to other sets of objects, except for these changes
- Polymorphism ("many sizes") in which an object determines itself Which methods are to run, so that you can depend on the language to run your requests correctly.
Now, as far as comparison is concerned:
The first question is "square" vs. "prototype". This idea originally started in Simula, where with each class based model, each group represented a group of objects that shared the same position location (read "possible value") and shared similar actions, causing one The equivalence classes were made. If you look back at Smalltalk, because you can open a class and add methods, it is effectively the same as you can in JavaScript.
Later OO languages are a constant type of inquiry, so we have the assumption of a set class set at compile time. In the open-class version, you had more flexibility; In the new version, you had the ability to check some kind of accuracy on the compiler, which would otherwise require testing. In the "class-based" language, time of copy occurs in compilation, in a prototype language, the operating prototype is stored in the data structure, which is copied and modified in run-time. In essence, however, a class is still the equality class of all things that shares the same state and methods. When you add a method for prototype, you are effectively making an element of a new equivalent class.
Now, why do you do this? Mainly because it makes for a simple, logical, elegant system at run time. Now, to create a new object, to make a new class or , you just need to make a deep copy, copy all the data and prototype data structure. A method named by always has to ask a dictionary for implementation.
The reason for this is that the script is finished in Javascript / ECMA basically that when we started this 10 years ago, we were working with very less powerful computers and very less sophisticated browsers. . Selecting a prototype-based method means that translators can be very easy while preserving the desirable properties of object orientation.
Comments
Post a Comment