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

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.

主站蜘蛛池模板: 寿宁县| 仙桃市| 白朗县| 普宁市| 邹城市| 洱源县| 冕宁县| 南溪县| 福州市| 慈溪市| 大城县| 额敏县| 巴塘县| 高邮市| 基隆市| 永福县| 通辽市| 扎囊县| 虞城县| 大连市| 聂拉木县| 永城市| 上思县| 丘北县| 双鸭山市| 北碚区| 娱乐| 石城县| 西乌珠穆沁旗| 西乡县| 时尚| 托里县| 宣武区| 新巴尔虎左旗| 旺苍县| 靖州| 文化| 遵义县| 越西县| 张家界市| 理塘县|