Javascript Prototype
Javascript Prototype
September 20, 2022
Prototype-based Object oriented language
- javascript is, different from java/c#(class-based ool), a prototype-based object oriented language
- js uses prototype to implement inheritance
Prototype
- every object in js has (at least) a prototype which has properties and methods
var date = new Date(); // Date.prototype && Object.prototype
- when a function is declared, it can be a constructor for an object using “new” keyword in front of it
- also, Prototype Object is created for the function and we can access to the Ojbect using “prototype” property of the function
- Prototype Object has constructor and __proto__(Prototype Link) property
- __proto__(Prototype Link) points to the ancestor’s Prototype Object