Why is this code not working?
function Person(name){ this.name = name; } Person.prototype.greet = function(otherName){ return "Hi " + otherName + ", my name is " + name; } Why is this code not working?
function Person(name){ this.name = name; } Person.prototype.greet = function(otherName){ return "Hi " + otherName + ", my name is " + name; } It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
Person.prototype.greet = function(otherName){ return "Hi " + otherName + ", my name is " + this.name; } Missing this keyword
var dave = new Person("Dave"); var hello = dave.greet("Alan"); // "Hi Alan, my name is Dave"; Source: https://ru.stackoverflow.com/questions/527452/
All Articles
namevariable in thegreetfunction does not exist - andreymal