Есть ли способ иметь полиморфизм в наследовании виджета в пользовательском интерфейсе jQuery?
Например, я хочу сделать что-то вроде:
$.widget('tr.fatherClass', {
getValue: function() {
return null;
}
...
});
// sonClass1: extends from the father
$.widget('tr.sonClass1', $.tr.fatherClass, {
getValue: function() {
return this._fooFunction1();
}
...
});
// sonClass2: extends from the father
$.widget('tr.sonClass2', $.tr.fatherClass, {
getValue: function() {
return this._fooFunction2();//
}
...
});
// create an instance of a "sonClass"
$('#foo1').sonClass1(options);
$('#foo2').sonClass2(options);
Затем я хочу использовать метод getValue без знания имени класса son:
$('#foo1').fatherClass('getValue'); // run _fooFunction1() of sonClass1
$('#foo2').fatherClass('getValue'); // run _fooFunction2() of sonClass2
Но это невозможно:
jquery.js:250 Uncaught Error: cannot call methods on variable prior to initialization; attempted to call method 'getValue'
В форуме JQuery Скотт Гонсалес объясняет, что "Создание виджета создает только один виджет, а не каждый виджет в цепочке прототипов" ссылка
Есть ли способ обхода или решения, чтобы сделать это элегантным способом?