JavaScript prototype property
Definition and Usage
prototype property allows you to add properties and methods to an object
Note: Prototype is a global property that applies to all Javascript objects.
grammar
object.prototype.name=value
Browser Support
All major browsers support prototype property
Examples
Examples
Applicable prototype property of the object to add attributes:
<script>
function employee(name,jobtitle,born)
{
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
}
var fred=new employee("Fred Flintstone","Caveman",1970);
employee.prototype.salary=null;
fred.salary=20000;
document.write(fred.salary);
</script>
function employee(name,jobtitle,born)
{
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
}
var fred=new employee("Fred Flintstone","Caveman",1970);
employee.prototype.salary=null;
fred.salary=20000;
document.write(fred.salary);
</script>
Examples of the above output:
20000
try it"
JavaScript String Object