You do not know the JS series (40) - What is the class

Good design is the data and its associated behavior and packing (package) up, which is sometimes referred to as data structures in a formal computer science

A string of characters used to represent a word or phrase is commonly referred to as a string. Character is the data. But more often than not you care about what the data are, but what can be done on the data, so data on such behavior can be applied (calculated length, add data, search, etc.) are designed to String class methods. So a string is the String class instance , that is, it is a package that contains character data and functions we can apply on the data

"Car" can be seen as a "vehicle" is a special case. It is defined as the Car class and the Vehicle class in software. Defines the Vehicle may contain engine, manned the ability to do it a big, these are the Vehicle behavior. We defined in the Vehicle is something for all types of vehicles involved. When you define a Car, just declare it inherits this basic definition of the Vehicle, Car definition is a special class of common definitions of Vehicle

Although the same Vehicle Car and defines a method, but the data may be different instances of each vehicle such as the vehicle identification number unique

This is the class, inheritance and instantiation

Another core concept of class is polymorphic , said the concept is universal behavior of the parent class can be subclassed by a more specific behavior rewritten. Class theory is strongly recommended that a parent and child classes use the same method name to represent a specific behavior, so that subclasses override the parent class. After we will see, this will reduce the JS code readability and robustness of the code.

Guess you like

Origin www.cnblogs.com/wzndkj/p/12610129.html