You set the property prototypeto an instance created new Employeethat does nothing to connect the prototype chain. The property prototypebecomes a function Employee. This property is then used to set the internal property of [[Prototype]]objects created with new Employee.
So, suppose you want to Employeebe a subclass People, you would do it like this:
var Person = function() {
this.FirstName = "John";
this.LastName = "Doer";
};
var Employee = function() {
Person.call(this);
this.DateHired = "June 30";
};
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;
var employee1 = new Employee();
console.log(employee1.DateHired);
console.log(employee1.FirstName);
Run code, , 2016 , : class ES2015 (, ), :
class Person {
constructor() {
this.FirstName = "John";
this.LastName = "Doer";
}
}
class Employee extends Person {
constructor() {
super();
this.DateHired = "June 30";
}
}
const employee1 = new Employee();
console.log(employee1.DateHired);
console.log(employee1.FirstName);