官术网_书友最值得收藏!

A classless society

JavaScript does not have classes. But as in other languages, we would like to tell the interpreter that it should build our myCar object following a certain pattern or schema or blueprint  it would be quite tedious to create every car object from scratch, manually giving it the attributes and methods it needs every time we build it.

If we were to create 30 car objects based on the Car class in Java, this object-class relationship provides us with 30 cars that are able to drive and honk without us having to write 30 drive and honk methods.

How is this achieved in JavaScript? Instead of an object-class relationship, there is an object-object relationship.

Where in Java our myCar, asked to honk, says go look at this class over there, which is my blueprint, to find the code you need, JavaScript says go look at that other object over there, which is my prototype, it has the code you are looking for.

Building objects via an object-object relationship is called prototype-based programming, versus class-based programming used in more traditional languages like Java.

Both are perfectly valid implementations of the object-oriented programming paradigm  it's just two different approaches.

主站蜘蛛池模板: 连江县| 阜城县| 晋中市| 延寿县| 汾阳市| 绥宁县| 贵德县| 梅河口市| 赣州市| 彭州市| 达尔| 宣化县| 安达市| 东阳市| 安远县| 临沭县| 汕尾市| 沈丘县| 谷城县| 阆中市| 杂多县| 阿瓦提县| 米脂县| 建德市| 绍兴县| 南城县| 高州市| 文登市| 涟水县| 阳城县| 安顺市| 灌南县| 资阳市| 昌图县| 南召县| 凤山市| 桂平市| 桦川县| 江山市| 丘北县| 襄垣县|