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

Example Analysis of static method of javascript Class

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this article Xiaobian for you to introduce in detail the "javascript class static method instance analysis", the content is detailed, the steps are clear, the details are handled properly, I hope this "javascript class static method instance analysis" article can help you solve your doubts, following the editor's ideas slowly in-depth, together to learn new knowledge.

The static method of a class in JavaScript is a method modified with the static keyword, also called a class method; before instantiating an object, a static method can be called through the class name. method name, and static methods cannot be called on the object, only in the class.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

Javascript class static method

A static method is a method modified by the static keyword, also known as a class method, which belongs to a class, but does not belong to an object, and can be instantiated by the class name. The static method is called by the method name.

Static methods cannot be called on an instance of a class, but should be called through the class itself. Cannot be called on an object, it can only be called in a class.

Examples are as follows:

Class Tripple {static tripple (n = 1) {return n * 3;}} / / correct usage console.log (Tripple.tripple ()); / / 3Accord / the following is the wrong use let tp = new Tripple (); console.log (tp.tripple ()); / / 'tp.tripple is not a function'.

An error will be reported when the instance object calls a static method:

Read this, the "javascript class static method instance analysis" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, 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