以下代码是什么意思?

时间:2021-08-04 19:55:14

I didn't understand what this code does:

我不明白这段代码的作用:

.bind(this);

(I took this code from zurb foundation dropdown plugin)

(我从zurb foundation dropdown插件中获取此代码)

.on('mouseleave.fndtn.dropdown', '[data-dropdown], [data-dropdown-content]', function (e) {
      var $this = $(this);
      self.timeout = setTimeout(function () {
        if ($this.data('dropdown')) {
          var settings = $this.data('dropdown-init');
          if (settings.is_hover) self.close.call(self, $('#' + $this.data('dropdown')));
        } else {
          var target = $('[data-dropdown="' + $(this).attr('id') + '"]'),
              settings = target.data('dropdown-init');
          if (settings.is_hover) self.close.call(self, $this);
        }
      }.bind(this), 150);
})

Is it compatible with jQuery 3? http://jquery.com/upgrade-guide/3.0/#deprecated-bind-and-delegate

它与jQuery 3兼容吗? http://jquery.com/upgrade-guide/3.0/#deprecated-bind-and-delegate

1 个解决方案

#1


0  

bind will set this inside the anonymous function to this of the from jQuery provided one.

bind会在匿名函数里面设置这个来自jQuery提供的函数。

Consider it like:

考虑它像:

(function() {
    console.log(this); // "foo"
}.bind("foo"))();

See the MDN documentation for more info ...

有关详细信息,请参阅MDN文档...

It has nothing to do with jQuery.bind()!

它与jQuery.bind()无关!

#1


0  

bind will set this inside the anonymous function to this of the from jQuery provided one.

bind会在匿名函数里面设置这个来自jQuery提供的函数。

Consider it like:

考虑它像:

(function() {
    console.log(this); // "foo"
}.bind("foo"))();

See the MDN documentation for more info ...

有关详细信息,请参阅MDN文档...

It has nothing to do with jQuery.bind()!

它与jQuery.bind()无关!