String prototype Property - Javascript String

Javascript examples for String:prototype

Description

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

Return Value:

A reference to the String.prototype object

The following code shows how to Use the prototype property to add a new property to all objects of a given type:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
function employee(name, jobtitle, born) {
    this.name=name;/* ww  w .j  ava 2  s  .  c  o  m*/
    this.jobtitle=jobtitle;
    this.born=born;
}
employee.prototype.salary = 2000;

var fred = new employee("Mary", "Programmer", 1990);
document.getElementById("demo").innerHTML = fred.salary;
</script>

</body>
</html>

Related Tutorials