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

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.

主站蜘蛛池模板: 大悟县| 揭东县| 汪清县| 丰原市| 寻乌县| 西乡县| 新田县| 黎川县| 云安县| 马山县| 永泰县| 虎林市| 三江| 彭阳县| 石屏县| 藁城市| 师宗县| 府谷县| 远安县| 栾川县| 滦南县| 信阳市| 兴海县| 灌阳县| 修水县| 陕西省| 邵武市| 洛川县| 自贡市| 长白| 武平县| 金堂县| 都江堰市| 大宁县| 清水县| 招远市| 囊谦县| 霍林郭勒市| 永善县| 甘谷县| 松滋市|