Why my person doesn't say "Hello" when calling one self method ? How to fix this?
var Person = (function () {
function Person() {
this.prototype.say();
}
Person.prototype.say = function() {
alert("hello");
}
return Person;
})();
var person = new Person();
Personvariables.Person's prototype you're assigning to. You want to assign to the outerPerson.prototype, but instead you're assigning to the inner one.return Person;They're the same thing. It's assigned to the prototype of the "inner"Personwhich is then returned and assigned to the "outer"Person. They're using an IIFE.