gpt4 book ai didi

javascript 对象递归函数

转载 作者:行者123 更新时间:2023-12-02 16:10:18 26 4
gpt4 key购买 nike

大家好,我在 yui 对象中有以下函数:

fun1: function (x){
....
if (condition)
this.fun1(x-1);
}

但我在 Debug模式下看到指令 this.fun1(x-1) 引发错误:未捕获的类型错误:未定义不是函数怎么解决呢?

最佳答案

在用于定义对象的对象文字表示法中,避免使用 this,因为 this 引用窗口对象。相反,您可以使用正在创建属性的对象名称。

var obj = {
testfunction: function() {
obj.testfunction();
}
};

关于javascript 对象递归函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30279292/

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