JSFiddle - React, Tailwind, and code Playground
by Andrew Ahn
JavaScript
function Person(){
this.sayHI=function(){}
};
//This will create Student Class
function Student(){};
Student.prototype=new Person();
Student.prototype.sayHI=function(l){
return "Hi! I am a Student";
}
//This will create Teacher Object
function Teacher(){};
Teacher.prototype=new Person();
Teacher.prototype.sayHI=function(){
return "Hi! I am a Teacher";
}
var sObj=new Student();
//This will check if the student
//object is instance of Person or not
//if not it won't execute our alert code.
if (sObj instanceof Person) {
alert("Hurry! JavaScript supports OOps" + sObj.sayHI());
}