4

Let's suppose I want to change the render function in bootstrap-typeahead library. http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js

One way to active this goal is to make:

_.extend($.fn.typeahead.Constructor.prototype, {
    render: function (items) {
      // some code
    }
});

Let's suppose I want to redefine the render function just for a specific element like…</p>

element.typeahead({
    minLength: 3,
    source: getSource
});

How should I redefine the render function in order to be valid just for this element?

P.S.:
I am using jquery and underscore

4

1 回答 1

1

也许你可以先克隆它?

$.fn.typeaheadCustom = $.fn.typeahead;

_.extend($.fn.typeaheadCustom.Constructor.prototype, {
    render: function (items) {
      // some code
    }
 });

element.typeaheadCustom({
    minLength: 3,
    source: getSource
});

更新

您可能需要对其进行深度克隆:

$.fn.typeaheadCustom = $.extend(true, $.fn.typeahead, {});
于 2012-08-30T09:54:36.543 回答