Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无对象的访问方法(如静态)_Jquery_Constructor_Properties - Fatal编程技术网

Jquery 无对象的访问方法(如静态)

Jquery 无对象的访问方法(如静态),jquery,constructor,properties,Jquery,Constructor,Properties,我想在不创建对象或调用document.ready事件的构造函数的情况下调用类方法。我尝试了不同的选择,但没有任何效果 var objReportsInterface; 类ReportsInterface扩展了ReportBase{ 建造师{ 超级的 objReportsInterface=this; } 子类别{} } $document.readyfunction{ $dropdown.在“更改”功能上 objReportsInterface.subCategories; } } 要创建静

我想在不创建对象或调用document.ready事件的构造函数的情况下调用类方法。我尝试了不同的选择,但没有任何效果

var objReportsInterface; 类ReportsInterface扩展了ReportBase{ 建造师{ 超级的 objReportsInterface=this; } 子类别{} } $document.readyfunction{ $dropdown.在“更改”功能上 objReportsInterface.subCategories; } }
要创建静态方法(即附加到构造函数本身而不是实例的方法),请使用静态:

然后


只想在document.ready中调用类方法,而不创建object我面临的一个问题是它不允许我在类中定义变量。当我这样做的时候,就像var x;据说是意外的性格。有什么已知的问题吗?@NeerajVerma-我不知道你所说的在类中定义变量是什么意思。在函数/方法中定义变量,而不是在类中定义变量。在上面的子类别中这样做当然没有问题。请查看和/或类似参考以了解有关类语法的更多信息。
class ReportsInterface {
    // ...

    static subCategories() {
        // ...
    }
}
$("dropdown").on('change', function()
    ReportsInterface.subCategories();
});