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

时间:2011-01-25 02:42:16

标签: javascript jquery jquery-ui inheritance override

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

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

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

this.element is undefined
this.originalTitle = this.element.attr('title');
jquery...5667348 (line 5864)

我怎么称呼那种“超级”方法?

jQuery UI版本1.8.8

1 个答案:

答案 0 :(得分: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.
  }
});