Javascript >> Add Methods After Inheritance
A constructor function that inherits its prototype object from a supertype constructor function can still have its own methods in addition to inherited methods.
For example, BlogRecord is a constructor that inherits its prototypefrom Record:
For example, BlogRecord is a constructor that inherits its prototypefrom Record:
function Record() { }
Record.prototype.oldRecord= function() { console.log("old record"); };
function BlogRecord() { }
BlogRecord.prototype = Object.create(Record.prototype);
BlogRecord.prototype.constructor = BlogRecord;
BlogRecord.prototype.newRecord=function(){console.log("new record");}
let record= new BlogRecord();
record.oldRecord();
record.newRecord();
Comments