古い質問であることはわかっていますが、古いプロジェクトのバグを修正する必要があり、この種のパッチに問題がありました。
options オブジェクトを介して関数を使用できるようにしてから、特定のロジックをそこに配置することをお勧めします。
パッチ:
(function monkeyPatchJQueryAutocomplete($) {
/**
* Proxies a private
* prototype method to the
* options Object
*
* @param {Object} obj
* @param {String} funcName
*/
function proxyPrivateMethodToOptions(obj, funcName) {
var __super = obj.prototype[funcName];
obj.prototype[funcName] = function() {
if (this.options[funcName]) {
return this.options[funcName].apply(this, arguments);
}
return __super.apply(this, arguments);
};
}
// Make the private _renderItem
// method available through the options Object
proxyPrivateMethodToOptions($.ui.autocomplete, '_renderItem');
// We can do this for other methods as well:
proxyPrivateMethodToOptions($.ui.autocomplete, '_renderMenu');
}($));
使用例:
$('.some-input').autocomplete({
_renderItem: function(ul, item) {
console.log('here we can reference the old func via: ', __super);
return $("<li>")
.append($("<a>").text(item.label))
.appendTo(ul);
}
});