Javascript Practice Day 3 : Javascript Prototype
Javascript Prototype : we use the prototype keyword with the constructor function and that function
will be accessed from outside .
1)The function is loaded only once and its shared among all the objects created upon the constructor functions
2)Allows to override the function if function
function Employee(name)
{
this.name= name;
}
Employee.prototype.getName = function(){
return this.name;
}
var e1= new Employee("John");
var e2= new Employee("Rambo");
document.write(e1.getName() + "<br/>");
document.write(e2.getName() + "<br/>");
Comments
Post a Comment