...

/

Solution Review: Prototype Property

Solution Review: Prototype Property

This lesson will explain the solution to the problem in the previous lesson.

We'll cover the following...

In the previous lesson, you were given the following code to modify.

Press + to interact
function func1(name){
this.name = name;
}
var obj1 = new func1("Bran");
func1.prototype = {
talk: function(){
console.log ("Welcome " + this.name);
}
}
function display(){
var obj2 = new func1("Jon");
obj2.talk() // works
obj1.talk() // doesn't work
}
display()

Solution #

Press + to interact
function func1(name){
this.name = name;
}
var obj1 = new func1("Bran");
func1.prototype.talk = function(){
console.log ("Welcome " + this.name);
}
function display(){
var obj2 = new func1("Jon");
obj2.talk()
obj1.talk()
}
display()

Explanation #

This challenge tests your understanding of ...