Description
The prototype property allows the addition of properties and methods to an object.
This property has the form:
object.prototype.name=value
Note: Prototype is a global property which is available with almost all JavaScript objects.
Examples
The following example shows the basic use of this property.
<script>
function employee(f_name, l_name, hire_date)
{
this.f_name = f_name;
this.l_name = l_name;
this.hire_date = hire_date;
}
var jsmith = new employee("John", "Smith", "06/07/2007");
employee.prototype.salary = null;
jsmith.salary = 56000;
document.write(jsmith.f_name);
document.write("<br />");
document.write(jsmith.l_name);
document.write("<br />");
document.write(jsmith.hire_date);
document.write("<br />");
document.write(jsmith.salary);
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|