- The Node Craftsman Book
- Manuel Kiessling
- 205字
- 2021-07-02 23:36:52
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.
- Linux設備驅動開發詳解:基于最新的Linux4.0內核
- Getting Started with oVirt 3.3
- 網絡操作系統:Windows Server 2003管理與應用
- Ubuntu Linux操作系統
- Ganglia系統監控
- Windows Phone 7.5 Data Cookbook
- 高性能Linux服務器構建實戰:運維監控、性能調優與集群應用
- RESS Essentials
- Linux運維最佳實踐
- 直播系統開發:基于Nginx與Nginx-rtmp-module
- Linux服務器配置與管理
- 鴻蒙操作系統設計原理與架構
- OpenHarmony開發與實踐:基于紅莓RK2206開發板
- Getting Started with Citrix XenApp 6.5
- 微軟360度