X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript String prototype Property

JavaScript String Reference JavaScript String Reference

Example

Use the prototype property to add a new property 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;

var fred = new employee("Fred Flintstone", "Caveman", 1970);

The value of fred.salary will be:

2000

Try it yourself »


Definition and Usage

The prototype property allows you to add new properties and methods to existing object types.

Note: Prototype is a global property which is available with almost all JavaScript objects.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The prototype property is supported in all major browsers.


Syntax

object.prototype.name = value


Technical Details

Return Value: A reference to the String.prototype object
JavaScript Version: 1.1


JavaScript String Reference JavaScript String Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook