Simple class example

by Arnaud Buchholz

JavaScript

function Person (firstName, lastName) {
	this.firstName = firstName;
  this.lastName = lastName;
}

Person.prototype = {

	firstName: "",
  lastName: "",

	getFullName: function () {
  	return this.firstName + " " + this.lastName;
  }
};

function Student (studentId, firstName, lastName) {
	Person.call(this, firstName, lastName);
  this.studentId = studentId;
}

Student.prototype = Object.create(Person.prototype);
Object.assign(Student.prototype, {

	studentId: "",

	getStudentInfo: function() {
    return this.studentId + " " + this.lastName + ", " + this.firstName;
  }

});

var student = new Student(1, "Bob", "Smith");

console.log(student.getFullName());
console.log(student.getStudentInfo());