Prototype Property in Javascript Object

September 19, 2017

Prototype property of object points to another object in javascript.
We will see how we can use the prototype property

function Product(name){
    this.name=name
}

Product.prototype.price=1
Product.prototype.getDiscount=function(){
    return this.price*5/100
}

var p= new Product('Fanta')

Now you can call the getDiscount() to get the discount
>console.log("Discount is "+p.getDiscount())
>Discount is 0.05