call a public static property on an instance of a class in javascript

To call a public static property on an instance of a class in JavaScript, you need to access the property through the constructor function of the class rather than on the instance itself.

Here is an example:

index.tsx
class MyClass {
  static myStaticProperty = "Hello, world!";
}

const myInstance = new MyClass();
console.log(MyClass.myStaticProperty); // Output: "Hello, world!"
console.log(myInstance.myStaticProperty); // Output: undefined
227 chars
8 lines

As you can see, accessing the static property on the class MyClass directly returns its value, while accessing it on an instance myInstance returns undefined.

gistlibby LogSnag