简体   繁体   中英

What does the below code mean?

I didn't understand what this code does:

.bind(this);

(I took this code from zurb foundation dropdown plugin)

.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

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

Consider it like:

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

See the MDN documentation for more info ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM