I want to check my idea is correct or not?
Codes:
function Person(firstname, lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
Person.prototype.getFullName = function () {
return this.firstname + ' ' + this.lastname;
}
var john = new Person('Melo','Tang');
I call the code in the following picture "function constructor".
function Person(firstname, lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
When the program run to this line
var john = new Person('Melo','Tang');
JS will use prototype chain to add the getFullName function in the "function constructor" Object and new a empty Object like following picture am I right?
