Course recommendation:
- Föregående sida padStart()
- Nästa sida repeat()
- Gå tillbaka till föregående nivå JavaScript String referenshandbok
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 prototypes of objects not under your control.
- You should not change the prototypes of built-in JavaScript data types, such as:
- Strings
- Arrays
- Dates
- Booleans
- Function
- Objects
Please only change the prototypes of objects you create yourself.
prototype property
JavaScript prototype
Properties allow you to add new properties to objects:
Instance
function Person(first, last, age, eyecolor) { this.firstName = first; this.lastName = last; this.eyeColor = eyecolor; } Person.prototype.nationality = "English";
Browser support
prototype
It is ECMAScript1 (ES1) feature.
All web browsers fully 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 |
- Föregående sida padStart()
- Nästa sida repeat()
- Gå tillbaka till föregående nivå JavaScript String referenshandbok