Home  >  Article  >  Web Front-end  >  How to use prototype property

How to use prototype property

青灯夜游
青灯夜游Original
2019-02-15 17:11:202971browse

The prototype attribute is used to add attributes and methods to objects. The syntax for using this attribute is "object.prototype.name=value".

How to use prototype property

The operating environment of this article: Windows 7 system, javascript version 1.8.5, Dell G3 computer.

Each constructor has an attribute called prototype, which is used to add properties and methods to the object. The following article will introduce you to the prototype attribute. I hope it will be helpful to you.

javascript prototype property

The prototype property gives you the ability to add properties and methods to an object.

Basic syntax of prototype attribute:

object.prototype.name=value

javascript Example of using prototype attribute

Below Let’s look at specific examples

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
function employee(name, jobtitle, born) {
  this.name = name;
  this.jobtitle = jobtitle;
  this.born = born;
}
employee.prototype.salary = 6000;
var fred = new employee("小华", "工程师", 1985);
document.getElementById("demo").innerHTML = fred.name+","+fred.jobtitle+",薪水为:"+fred.salary;
</script>
</body>
</html>

Renderings:

How to use prototype property

The above is the detailed content of How to use prototype property. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn