JSFiddle - React, Tailwind, and code Playground

by Kai

JavaScript

// Add the missing code to produce the expected result

function Person(name) {
    this.name = name;
}

Person.prototype.getName = function() {
    return this.name;
}

/* Some people do this, which works, but will 
   be wasteful on memory if a lot of Person objects
   are created. Each Person will have its own getName
   function. Using prototype above will re-use the same
   function across all Person instances

function Person(name) {
    this.name = name;
    this.getName = function() {
        return this.name;
    }
}

*/


var p1 = new Person('John');
var p2 = new Person('Dave');

alert( p1.getName() );
alert( p2.getName() );