Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript prototype property

JavaScript prototype property

String Object Reference JavaScript String object


Definition and Usage

The prototype property allows you to add properties and methods to an object.

Note: Prototype is a global property that applies to all JavaScript objects.

Syntax

object.prototype.name=value


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the prototype property.


Example

Example

Use the prototype property to add a property to an object:

function

employee

(

name

,

jobtitle

,

born

)

{

this

.

name

=

name

;

this

.

jobtitle

=

jobtitle

;

this

.

born

=

born

;

}

var

fred

=

new

employee

(

"

Fred Flintstone

"

,

"

Caveman

"

,

1970

)

;

employee

.

prototype

.

salary

=

null

;

fred

.

salary

=

20000

;

document

.

write

(

fred

.

salary

)

;

The output of the above example is:

20000

Try it »


String Object Reference JavaScript String object