jQuery UI Widget - 对象没有方法_super

时间:2013-06-04 13:10:58

标签: javascript jquery jquery-ui

调用基类方法似乎对我不起作用。 我有以下设置:

...
<div class='my'></div>
...

和Javascript

$.widget('tt.name1',{
    _create: function() {
        this.name = 'name'
        console.log('-->', this.name);
    }
});

$.widget('tt.name2',$.tt.name1, {
    _create: function() {
        this._super();
        /*$.tt.name1.prototype._create.call(this);*/
        this.name = 'name2'
        console.log('-->', this.name);
    }
});

$('.my').name1();
$('.my').name2();

在调用this._super()

时产生以下输出和错误
  

- &GT;命名
  未捕获的TypeError:对象#没有方法'_super'

these two链接表明它应该有效

try in action

1 个答案:

答案 0 :(得分:6)

这些示例使用jQuery 1.9中引入的小部件工厂。您的示例使用1.8.9。如果升级到1.9,您的代码将正常工作。