Course recommendation:
- Previous Page padStart()
- Next Page repeat()
- Go to Parent Directory JavaScript String Reference Manual
JavaScript String prototype property
prototype
Definition and usage
prototype
It is a property available to all JavaScript objects.
instance
Properties allow you to add new properties and methods to strings. prototype
Using
Properties 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);
Syntax object.prototype.name =
value
Warning
It is not recommended to change the prototype of objects not under your control.
- You should not change the prototype of built-in JavaScript data types, such as:
- Strings
- Arrays
- Dates
- Booleans
- Function
- Objects
Please only change the prototype of the object you created yourself.
prototype property
JavaScript prototype
Properties allow you to add new properties to an object:
instance
function Person(first, last, age, eyecolor) { this.firstName = first; this.lastName = last; this.eyeColor = eyecolor; } Person.prototype.nationality = "English";
browser support
prototype
is ECMAScript1 (ES1) feature.
All browsers fully support ES1 (JavaScript 1997):
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page padStart()
- Next Page repeat()
- Go to Parent Directory JavaScript String Reference Manual