Latest web development tutorials

JavaScript prototype property

String Object Reference JavaScript String Object

Definition and Usage

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

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

grammar

object.prototype.name=value


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support prototype property


Examples

Examples

Applicable prototype property of the object to add attributes:

<script>

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);

</script>

Examples of the above output:

20000

try it"


String Object Reference JavaScript String Object