- Hands-On Full Stack Web Development with Aurelia
- Diego Jose Argüelles Rojas Erikson Haziz Murrugarra Sifuentes
- 163字
- 2021-06-25 20:58:14
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.
- EJB 3.1從入門到精通
- 自動駕駛網絡:自智時代的網絡架構
- 6G潛在關鍵技術(下冊)
- 計算機網絡安全實訓教程(第二版)
- Web Application Development with R Using Shiny
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- 中小型局域網組建、管理與維護實戰
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- Bonita Open Solution 5.x Essentials
- 網管工具使用與技巧大全
- 無線傳感器網絡定位技術
- 一本書讀懂物聯網
- 走近奇妙的物聯網
- Building Microservices with Spring
- 網絡互聯技術(理論篇)