In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the method of setting members in nodejs". In daily operation, I believe that many people have doubts about the method of setting members in nodejs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the method of setting members in nodejs?" Next, please follow the editor to study!
Nodejs set members of the method: 1, create a js sample file; 2, through the "c. Name =" my circle "way in the object generated, attach member variables to it.
This article operating environment: Windows7 system, nodejs10.16.2 version, DELL G3 computer
How does nodejs set up its members?
Node.js defines member variables:
Node.js is a JavaScript runtime environment based on the Chrome V8 engine. Node.js uses an event-driven, non-blocking Istroke O model.
Node.js is the JavaScript running on the server. Let's take a look at how node.js defines member variables:
Member variable
Member variables are declared in the initialization function: this.r = r
Note that after the object is generated, you can also attach member variables to it, such as c.name = "my circle".
But unless there is a special need, I strongly advise you not to do so. That is, all members should be declared in the initialization function. I think this is a good style.
P.C = "ccc"; function p () {this.b= "ccc"} var d=new p (); var f=new p (); d.vaccoun33 politics (p.c); / / cccalert (d.c); / / undefinedalert (f.c); / / undefinedalert (p.b); / / undefinedalert (d.b); / / cccalert (f.b); / / cccalert (p.v); / / undefinedalert (d.v); / / 33alert (f.v); / / undefined
Member function
The standard form of a member function is as follows:
Cricle.prototype.area = function () {return 3.14 * this.r * this.r;}
This is very different from java or python or C++. But to help you understand, you can think of prototype as the base class.
Variables or methods in prototype are shared by all objects.
For example, the c.area () call eventually causes the interpreter to call Circle.prototype.area ().
There is a semantics that you can define variables in prototype compared to java and clockwise javascript which they don't have. Variables defined in prototype can be shared by all instances. So generally it should be a constant, for example: Circle.prototype.PI = 3.14.
Obviously, the variables and methods in prototype should be immutable. Each object instance should not take and modify the contents of the prototype. Although the language allows you to do this, it doesn't make any sense and violates object-oriented semantics.
It is recommended that all member functions be defined immediately next to the class definition. Instead of adding / modifying member functions to an object instance somewhere the code is running. The result is that the class definition of javascript is as close as possible to java. Make the code clearer.
At this point, the study on "what is the method of setting members in nodejs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.