This line of code effectively overwrites any previous values:
Dignitary.prototype = new Person(); // making Dignitary inherit Person
any call to the Person() function will overwrite any previous values set. Adding this to the last line of the code proves it:
console.log(p1.firstName) // undefined
Probably you wanted to do something like:
function Person()
{
//dummy function
}
Person.prototype = {
get firstName() {return this._firstName;},
set firstName(x) {this._firstName = x;},
get lastName() {return this._lastName;},
set lastName(x) {this._lastName = x;}
}
var person = new Person;
person.firstName = "Bruce";
person.lastName = "Lee"
console.log(person.firstName + " " + person.lastName);
function Dignitary()
{
//dummy function
}
Dignitary.prototype = Person.prototype;
var dignitary = new Dignitary;
dignitary.firstName = "Johny";
dignitary.lastName = "Bravo";
console.log(dignitary.firstName + " " + dignitary.lastName);
Note that using the defineGetter and defineSetter functions is deprecated.