Add new properties to an object constructor in JavaScript

Add new properties to an object constructor in JavaScript

Suppose we have a function WebsiteData() and it has two parameters(title,description).

function WebsiteData(pageTitle, pageDescription) {
    this.title = pageTitle;
    this.description = pageDescription;
}
Add a new property 'keywords' to this function WebsiteData().
WebsiteData.prototype.keywords = "my website keywords";

Sample code and demo is here

Demo

No comments:

Post a Comment