在一定时间后调用一个函数Jquery?

kam*_*aci 15 time jquery function

我正在检查Bram Jetten的js文件:

Notification.fn = Notification.prototype;

function Notification(value, type, tag) {
  this.log(value, type);
  this.element = $('<li><span class="image '+ type +'"></span>' + value + '</li>');
  if(typeof tag !== "undefined") {
    $(this.element).append('<span class="tag">' + tag + '</span>');
  }
  $("#notifications").append(this.element);
  this.show();
}

/**
 * Show notification
 */
Notification.fn.show = function() {
  $(this.element).slideDown(200);
  $(this.element).click(this.hide);
}

/**
 * Hide notification
 */
Notification.fn.hide = function() {  
  $(this).animate({opacity: .01}, 200, function() {
    $(this).slideUp(200, function() {
      $(this).remove();
    });
  });
}

...
Run Code Online (Sandbox Code Playgroud)

我为我的按钮分配了一个点击事件,当我点击该按钮时,它会调用一个新的通知:

new Notification('Hi', 'success');
Run Code Online (Sandbox Code Playgroud)

当我点击该通知时它也会关闭.但是,如果我在一段时间后没有点击它,我希望它自己关闭.我怎样才能调用隐藏功能,或者在它出现一段时间后将其关闭?

kam*_*aci 32

var that = this;

setTimeout(function() {   //calls click event after a certain time
   that.element.click();
}, 10000);
Run Code Online (Sandbox Code Playgroud)

这对我有用.