实例化类时,如何理解JavaScript静态方法也不可调用。 [英] How to understand `JavaScript static methods are also not callable when the class is instantiated`
本文介绍了实例化类时,如何理解JavaScript静态方法也不可调用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 mdn 上阅读了它。
原始值为:
I read it on mdn. The original is:
static
关键字定义了静态方法一堂课。静态方法是在不实例化其类的情况下调用的,并且在实例化该类时也无法调用。
The
static
keyword defines a static method for a class. Static methods are called without instantiating their class and are also not callable when the class is instantiated.
我认为 js中的static
与Java中的 static
相似,但有疑问的句子使我感到困惑。
I thought static
in js is similar to static
in java but the sentence in question confuses me.
推荐答案
相似。但是,Java允许在实例上调用静态方法:
It is similar. However, Java allows calling static methods on the instance:
p1.distance(p1, p2);
其作用与
Point.distance(p1, p2);
JavaScript中不允许使用第一个。
The first one is not allowed in JavaScript.
这篇关于实例化类时,如何理解JavaScript静态方法也不可调用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文