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 an ECMAScript1 (ES1) feature.

All modern browsers support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Related pages

JavaScript object

JavaScript object definition

JavaScript object method

JavaScript object property