Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is there a variable improvement in es6's class?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "is there a variable improvement in the class of es6", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "the class of es6 has a variable improvement?" the article can help you solve your doubts.

There is no variable promotion for es6's class. There is a variable promotion in class in es5, so you can use the class first and then define the class, but in es6, the declaration of the class will not be promoted to the header. If you use the class first and then define it, an error will be generated, so you cannot use it first and then define it, and there will be no variable promotion in the class of es6.

This article operating environment: windows10 system, Vue2.9.6 version, DELL G3 computer.

Is there any variable improvement in es6's class?

There is no variable promotion in class.

Because ES6 does not promote the declaration of the class to the head of the code, you need to define it before you use it.

But ES5 is different. ES5 has variable promotion, which can be used first and then defined.

/ / ES5 can be used before definition, there is a variable to promote new A (); function A () {} / / ES6 cannot be used before definition, there is no variable promotion will report an error new B (); / / B is not definedclass B {}

There is no variable promotion (hoist) in the class, which is completely different from ES5.

New Foo (); / / ReferenceErrorclass Foo {}

In the above code, the ES6 Foo class is used first and defined later, which will report an error because ES6 does not promote the declaration of the class to the head of the code. The reason for this provision is related to the inheritance mentioned below, and it is necessary to ensure that the subclass is defined after the parent class.

{let Foo = class {}; class Bar extends Foo {}}

The above code will not report an error, because when Bar inherits Foo, Foo is already defined. However, if there is a promotion of class, the above code will report an error, because class will be promoted to the code header, and the let command will not be promoted, so when Bar inherits Foo, Foo has not been defined.

After reading this, the article "is there a variable improvement in the class of es6?" the article has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report