首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jquery库中重新定义方法的最佳方法

在jquery库中重新定义方法的最佳方法
EN

Stack Overflow用户
提问于 2012-08-30 17:49:46
回答 1查看 167关注 0票数 4

假设我想要更改bootstrap-typeahead库中的呈现函数。http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js

激活此目标的一种方法是:

代码语言:javascript
复制
_.extend($.fn.typeahead.Constructor.prototype, {
    render: function (items) {
      // some code
    }
});

假设我只想为…这样的特定元素重新定义呈现函数

代码语言:javascript
复制
element.typeahead({
    minLength: 3,
    source: getSource
});

我应该如何重新定义渲染函数,才能使其仅对此元素有效?

附言:

我使用jquery和下划线

EN

回答 1

Stack Overflow用户

发布于 2012-08-30 17:54:37

也许你可以先克隆它?

代码语言:javascript
复制
$.fn.typeaheadCustom = $.fn.typeahead;

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

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

更新

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

代码语言:javascript
复制
$.fn.typeaheadCustom = $.extend(true, $.fn.typeahead, {});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12194171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档