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

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.

主站蜘蛛池模板: 临漳县| 西和县| 特克斯县| 台州市| 霍城县| 富源县| 漯河市| 高密市| 象山县| 台东县| 江孜县| 青阳县| 沙河市| 钟祥市| 临邑县| 宜宾县| 正阳县| 阿坝县| 广西| 佳木斯市| 韶关市| 隆尧县| 酉阳| 阜阳市| 荆州市| 大连市| 锦州市| 西乌珠穆沁旗| 禄劝| 高台县| 阳东县| 元氏县| 盖州市| 堆龙德庆县| 黄骅市| 新闻| 息烽县| 太和县| 黄陵县| 郴州市| 淮北市|