JSFiddle - React, Tailwind, and code Playground
by Ebram
JavaScript
// Define the 'Person' Object
function Person() {
this.sayHello = function () {
alert('Hello there.');
};
}
// Define the Student constructor function
function Student() {}
// Inherit from Person
Student.prototype = new Person();
// Correct the constructor pointer, because it points to Person
Student.prototype.constructor = Student;
// Define new properties related to Student Object
Student.prototype.codeWith = function (code) {
alert('I code with ' + code);
};
var student1 = new Student();
student1.sayHello(); // we can use 'Person' Properties
student1.codeWith('JS'); // and use 'Student' Properties
// change base object implementation for 'sayHello' function
Student.prototype.sayHello = function () {
alert('hello I am a Student Object');
};
student1.sayHello();