- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Front end Development 2 Prototypes
        Vincent van Leeuwen edited this page May 27, 2020 
        ·
        1 revision
      
    Theres different kind of prototypes. You've got the Object.prototype, Function.prototype and Array.prototype.
Each of these prototypes got a set of functions that you can use. For instance, you can use pop() on an array to delete the last entry.
But you can also create your own prototypes.
Lets say you have an object named "dog" that contains the color "beige" and the breed "labrador"
let dog = {
breed: "labrador"
color: "beige";
}You can then create a new function for this dog by using the .prototype on the dog and naming your new function, in this instance that is "getBreed"
dog.prototype.getBreed = function() {
return this.breed
}You can now use that function by calling dog.getBreed(); It will print: "labrador"
source: https://medium.com/backticks-tildes/javascript-prototypes-ee46810e4866