Correctly declare static variables in JavaScript classes

前端 未结 2 1559
孤街浪徒
孤街浪徒 2021-01-19 13:37

In my code, I do the following (very simplified):

class AddOrSelectAddress {
    static body; // <-- Error

    static async open() {
        await $.get(         


        
2条回答
  •  盖世英雄少女心
    2021-01-19 14:11

    Static methods are perfectly fine to use. However static properties are a recent addition that dont work in all browsers yet. It works in Chrome but like you said not in firefox. Please take a look at this article as it backs up my answer : https://javascript.info/static-properties-methods. To fix your issue you could declare the variable inside your static method.

提交回复
热议问题