javascript - 在 jQuery 中,当您处于each() 的范围内时,如何解析 "this"的范围?

标签 javascript jquery scope this

我创建了一个对象,并且该对象中有一个 setup() 方法。

this.debug = function (){...}

this.setup = function(){    

  var fieldsets = form.children("fieldset");

  fieldsets.each(function(){        
    this.debug($(this).attr("class")));
  });


}

我试图调用 this.debug ,它在对象的范围内,但不在每个对象的范围内,因为这是一个不同的 this...

如何访问 this.debug?

最佳答案

在 this.debug 之后说 var that = this,然后执行 that.debug

关于javascript - 在 jQuery 中,当您处于each() 的范围内时,如何解析 "this"的范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2291355/

相关文章:

javascript - 如何将 "slugified-title"转换为 "Slugified Title"

jquery - 使用 jQuery 检索按钮值

javascript - Node.js 中循环异步函数内 undefined variable

javascript - 使用 useContext 时 props.history 未定义?

php - 如何通过使用 php、javascript、wsdl 调用 Web 服务来发送电子邮件?

javascript - 如何将 Confluence 插件与 jQuery 代码结合起来?

javascript - jQuery 迭代表并选择下拉列表

jquery - 滑动悬停菜单文本切换不适合

perl - 在 Perl 子例程中在哪里定义局部临时变量?

.NET 即时超出范围通知?