Prototyped
JavaScript uses prototypes instead of classes for inheritance. It is possible to emulate all OOP characteristics using just prototypes:
function Person(first, last, age) {
this.firstName = first;
this.lastName = last;
this.age = age;
}
var diego = new Person('Diego', 'Arguelles', 26)
diego.nationality = 'Peruvian'
console.log(diego)
// Person {firstName: "Diego", lastName: "Arguelles", age: 26, nationality: "Peruvian"}
Person.prototype.career = 'Engineering'
console.log(diego.career) // Engineering
That being said, what is exactly a prototype? Different from objects, one prototype does not have a closed structure. In objects, we define standard properties and we just have these properties for work, since JavaScript is not completely an object-oriented language, we have the advantage to add, remove, or change properties and values of our prototypes depending on our needs.
We can modify prototype attributes at runtime. Note that even if you can modify any prototype, you should only modify yours. If you modify standard prototypes (for example, the array prototype) you will encounter very weird bugs in your application.
- 社交網(wǎng)絡(luò)對齊
- Web安全防護(hù)指南:基礎(chǔ)篇
- SEO 20日
- Learning QGIS 2.0
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- Learning Karaf Cellar
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- 局域網(wǎng)組建、管理與維護(hù)項目教程(Windows Server 2003)
- PLC、現(xiàn)場總線及工業(yè)網(wǎng)絡(luò)實用技術(shù)速成
- Mastering JavaFX 10
- 物聯(lián)網(wǎng)通信技術(shù)
- 通信原理及MATLAB/Simulink仿真
- 6G無線網(wǎng)絡(luò)空口關(guān)鍵技術(shù)
- ReasonML Quick Start Guide
- 物聯(lián)網(wǎng)概論