In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "what is the difference between es6 static properties and instance properties". The editor shows you the operation process through an actual case, the operation method is simple and fast, and it is practical. I hope this article "what is the difference between es6 static properties and instance properties" can help you solve the problem.
Differences: 1, the static property is the property of the class itself, which can only be called in the class itself, while the instance property is the property of the instance object; 2, the instance object cannot call the static property, but the class can call the instance property; 3, the static property has only one declaration method, the syntax "class name. Attribute name = value", while instance properties have a variety of declaration methods, which are defined by "attribute name = value" in the example class.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Static is not inherited by the instance, it belongs to the class itself, and the instance cannot be inherited or invoked, just like the scope.
Static attribute: the property of the class itself, which can only be called in the class itself. The instance object cannot be called to the static property, and can only be called by the class itself. Of course, the subclass can also call the static property of the parent class.
Instance property: it is the instance property that can be called by the instance object. Remember that the instance cannot call the static property of the class, but the class can call the instance property.
Declare static properties:
Just like ordinary Object add attributes, object.a = value; (currently the only way); it has been proposed to add the static keyword to the class, but it has not been implemented yet
Class F {}; F.B = "static properties of the parent class"; / / add static methods to class F
Declare a static method: precede the method with the static keyword
Class Foo {static bar () {/ / the this in the static method points to the class itself instead of the instance this.baz ();} static baz () {/ / static method console.log ('hello');}} Foo.bar () / / hellonew Foo () .bar (); / / if the instance cannot be called, an error will be reported
Declare instance properties:
1, defined in the class
Class MyClass {myProp = 42; constructor (props) {console.log (this.myProp); / / 42 this.name=props.name}} / / in the above code, myProp is the instance property of MyClass. On an instance of MyClass, you can read this property.
2, defined in constructor (classic in react)
Class ReactCounter extends React.Component {constructor (props) {super (props); / / you can have subclasses inherit this.state = {count: 0};}} / / equivalent to class ReactCounter extends React.Component {state = {count: 0};}
Summary of the differences between static properties and instance properties:
The static property is the property of the class itself and can only be called in the class itself, while the instance property is the property of the instance object and can be called by the instance object.
Instance objects cannot be called to static properties and can only be called by the class itself, while classes can call instance properties.
Static properties have only one declaration method, while instance properties have multiple declaration methods.
Instance properties are defined on the instance, either on the internal this of the constructor or on the instance after the constructor is instantiated.
Static properties, properties defined on top of the constructor. Can be accessed directly through the constructor.
This is the end of the content about "what are the differences between es6 static properties and instance properties". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.