gpt4 book ai didi

javascript - 在这里无法理解范围问题

转载 作者:行者123 更新时间:2023-11-30 09:03:30 25 4
gpt4 key购买 nike

我不明白为什么/如何完成这个相当简单的事情。如果有人能解释一下,那就太好了。

function Module(config) {
this.host = {Collapse: $('<a href="#" class="collapse">C</a>')};

function EnableCollapse() {
//I need to access host.Collapse here
this.host.Collapse.hide(); // Throws error
host.Collapse.hide(); //Throws error
}
}

如何在此函数中访问 Collapse?或者这些应该起作用,也许我还有其他问题?

最佳答案

function Module(config) {
var that = this;
that.host = {Collapse: $('<a href="#" class="collapse">C</a>')};

function EnableCollapse() {
//I need to access host.Collapse here
that.host.Collapse.hide(); // Throws error
}
}

关于javascript - 在这里无法理解范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7126698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com