JavaScript prototype property
Definition and Usage
The prototype property allows you to add properties and methods to an object.
Note: Prototype is a global property that applies 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 a property 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 »
JavaScript String object