继承自jQuery UI对话框并调用重写方法

Zar*_*doz 7 javascript jquery inheritance overriding jquery-ui

下面的简单代码描述了我的问题(至少我跳过这样):

$.widget("ui.mydialog", $.ui.dialog, {
  _create: function() {
    // How to call _create method of dialog?
  }
});
Run Code Online (Sandbox Code Playgroud)

我尝试$.ui.dialog.prototype._create()从上面的create方法中调用,但在Firebug中得到以下错误:

this.element is undefined
this.originalTitle = this.element.attr('title');
jquery...5667348 (line 5864)
Run Code Online (Sandbox Code Playgroud)

我怎么称呼那种"超级"方法呢?

jQuery UI版本1.8.8

Zar*_*doz 12

我想我刚刚找到了解决方案...... $.ui.dialog.prototype._create.call(this);

完整代码:

$.widget("ui.ajaxdialog", $.ui.dialog, {
  _create: function() {
    // Your code before calling the overridden method.
    $.ui.dialog.prototype._create.call(this);
    // Your code after calling the overridden method.
  }
});
Run Code Online (Sandbox Code Playgroud)

  • 对于jqueryui 1.9x,您可以简单地执行:`this._super('_ create');`上述解决方案仍然有效. (6认同)
  • 有趣.`_create`函数中的简单`this._super()`也可以.那可能是味道的问题. (2认同)