JavaScript prototypeProperty
Definition and Usage
The prototype property allows you to add properties and methods to objects.
Note:Prototype is a global property, applicable to all Javascript objects.
Syntax
object.prototype.name=value
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the prototype property.
Example
Example
Use the prototype property to add properties to an object:
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);
The output of the above example is:
20000
Try it Yourself »
Other Extensions
JavaScript String Object