Javascript Practice Day 3 : Method Override

Javascript Method Override : Method  overriding is possible with the help of  function prototype in constructor function . This is helpful if we are referring an external javascript file and wants to  overrride the function present there.The function to be overridden should be declared defined above the base function

//overridden funciton
Employee.prototype.getName= function(){
 return this.name.toUpperCase();   
}

//objects declared for the Employee class
var e1= new Employee("John");
var e2= new Employee("Rambo");

document.write(e1.getName() + "<br/>");
document.write(e2.getName() + "<br/>");

//Constructor function
function Employee(name)
{
    this.name= name;
}

//base function that will get overidden above
Employee.prototype.getName = function(){
    return this.name;
}





Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6