The prototype attribute is used to add attributes and methods to objects. The syntax for using this attribute is "object.prototype.name=value".
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:
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!