In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what does class refer to in javascript". In daily operation, I believe that many people have doubts about what class refers to in javascript. 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 does class mean in javascript?" Next, please follow the editor to study!
In JavaScript, class means "class", and the class keyword is used to define a template for a class, which can be understood as a collection of groups with the same properties and behavior, and the syntax is "class {set variables and methods}".
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
What does class mean in javascript
1. What is a class?
Here we can understand that a class is a collection of groups with the same attributes and behaviors. In es6, the concept of class is introduced for the first time, and a template of a class is defined by creating the class keyword.
2. Create a Class in js
Class Number {}
3. The construction method, instance property and instance method of implementing Class.
/ / Constructor class Number {/ / instance property constructor (id,age) {/ / this points to the current event this.id=id;this.age=age;} / / instance method num () {console.log ("hh");}} / / instantiate object var n1=new Number ("1", "2"); n1.num (1); console.log (n1.id); console.log (n1.age); var n2=new Number ("3", "4"); n2.num (2) Console.log (n2.id); console.log (n2.age)
Effect display:
Hh12hh34
4. Static properties and static methods of Class
/ / Constructor class Number {/ / static property calls a method static ppp=1;// instance property constructor (id,age) {/ / this points to the current event this.id=id;this.age=age;console.log (Number.ppp)} / / instance method num () {console.log ("hh");}} / / instantiate object var n1=new Number ("1", "2"); n1.num (1); console.log (n1.id); console.log (n1.age) Var n2=new Number ("3", "4"); n2.num (2); console.log (n2.id); console.log (n2.age)
Effect display:
1hh121hh34
5. Inheritance of class
/ / the parent class Father {/ / constructor cannot be inherited constructor () {console.log ("I am the father"); this.name= "father"}} / / the subclass class Son extend Father {/ / must execute the parent constructor constructor () {super (); / / execute the parent constructor console.log ("I am a son")}} var son=new Son;console.log (son.name)
Effect display:
I am the father and I am the son father. This is the end of the study on "what does class in javascript refer to?". I hope I can 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.