In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what is the use of the prototype method in javascript", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the use of prototype method in javascript" this article.
Javascript prototype is the prototype object of javascript, and all JavaScript objects inherit properties and methods from a prototype, that is, the prototype object.
This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.
JavaScript prototype (prototype object)
All JavaScript objects inherit properties and methods from a prototype (prototype object).
Prototype inheritance
All JavaScript objects inherit properties and methods from a prototype (prototype object):
The Date object inherits from Date.prototype. The Array object inherits from Array.prototype. The Person object inherits from Person.prototype.
All objects in JavaScript are instances of Object at the top of the prototype chain.
The JavaScript object has a chain pointing to a prototype object. When trying to access the properties of an object, it searches not only for the object's prototype, but also for the object's prototype and its prototype, searching up layer by layer until a name-matching property is found or the end of the prototype chain is reached.
Date objects, Array objects, and Person objects inherit from Object.prototype.
Add properties and methods
Sometimes we want to add new properties or methods to all existing objects.
In addition, sometimes we want to add properties or methods to the constructor of the object.
Using the prototype property, you can add new properties to the object's constructor:
Example
Function Person (first, last, age, eyecolor) {this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eyecolor;} Person.prototype.nationality = "English"
Of course, we can also use the prototype property to add new methods to the object's constructor:
Example
Function Person (first, last, age, eyecolor) {this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eyecolor;} Person.prototype.name = function () {return this.firstName + "" + this.lastName;}; this is all the content of the article "what's the use of prototype in javascript?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.