尤慕李 尤慕李 - 1 year ago 61
Javascript Question

How to understand `JavaScript static methods are also not callable when the class is instantiated`

I read it on mdn.
The original is:


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.


I thought
static
in js is similar to
static
in java but the sentence in question confuses me.

Answer Source

It is similar. However, Java allows calling static methods on the instance:

p1.distance(p1, p2);

which does the same thing as

Point.distance(p1, p2);

The first one is not allowed in JavaScript.