JavaScript object prototype property

Definition and usage

prototype It is a global property available for all JavaScript objects.

prototype Properties allow you to add new properties and methods to objects.

Instance

Use the prototype property to add new properties to all objects of a given type:

function employee(name, jobtitle, born) {
  this.name = name;
  this.jobtitle = jobtitle;
  this.born = born;
}
employee.prototype.salary = 2000;
const fred = new employee("Fred Flintstone", "Caveman", 1970);

Try it yourself

Syntax

object.prototype.name = value

Browser support

prototype It is ECMAScript1 (ES1) feature.

All modern browsers support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Stöd Stöd Stöd Stöd Stöd Stöd

Relaterade sidor

JavaScript-objekt

JavaScript-objektdefiniering

JavaScript-objektmethoder

JavaScript-objektsattribut