By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Extend Prototype (Class Inheritance and Prototypes)

+1 vote

Write a JS function which receives a class and attaches to it a property species and a function toSpeciesString(). When called, the function returns a string with format:

I am a <species>. <toString()>

The function toString is called from the current instance (call using this).


Your function will receive a class whose prototype it should extend.


There is no output, your function should only attach the properties to the given class’ prototype.


function extendClass(classToExtend) {


asked in JavaScript category by user andrew

1 Answer

0 votes

My solution:

class Person {
    constructor(name, email) { = name; = email;

    toString() {
        let className =;
        return `${className} (name: ${}, email: ${})`;

function extendClass(classToExtend) {

    classToExtend.prototype.species = 'Human';
    classToExtend.prototype.toSpeciesString = function () {
        return `I am a ${this.species}. ${this.toString()}`;

let gosho = new Person('gosho', '');
console.log('' + gosho);


answered by user Jolie Ann