Javascript 如何覆盖jquery中的现有函数

Javascript 如何覆盖jquery中的现有函数,javascript,jquery,javascriptmvc,Javascript,Jquery,Javascriptmvc,这是所有js的默认设置 getEditor: function(){ $( '#datatableEditor' ).remove(); var editor = $( '<div id="datatableEditor" class="popupEditor"/>' ); $( 'body' ).prepend( editor ); var dialog = $(editor).dialog({ title: 'Edit item'

这是所有js的默认设置

getEditor: function(){
    $( '#datatableEditor' ).remove();
    var editor = $( '<div id="datatableEditor" class="popupEditor"/>' );
    $( 'body' ).prepend( editor );

    var dialog = $(editor).dialog({
        title: 'Edit item',
        modal: true,
        width: 'auto',
        height: 'auto'
    });
getEditor:function(){
$('#datatableEditor')。删除();
变量编辑器=$('');
$(“正文”).prepend(编辑器);
变量对话框=$(编辑器).dialog({
标题:“编辑项目”,
莫代尔:是的,
宽度:“自动”,
高度:“自动”
});

现在我正在编写另一个js。我需要在我的js中覆盖
getEditor

您只需获得对函数“getEditor”的引用并为其分配另一个函数即可

getEditor:function(){
// new function will override the existing reference that getEditor already has.
}

您必须获取存储getEditor函数的对象,并使用引用对其进行更改。

您没有清楚地描述您的问题,但基于您在标题中提到的内容:

重写jquery中的现有函数

似乎您想要更改jQuery函数,它们的定义通常类似于
$.fn.getEditor
如果是这种情况,您应该执行以下操作:

(function ($) {
    var oldGetEditor = $.fn.getEditor;
    $.fn.getEditor = function() {

       //you can call the oldGetEditor here if you want
    };
})(jQuery);

您要更改/实施的内容我需要更改标题。这对所有人都一样,但我需要将标题更改为操作名称
someObject.getEditor = function(){
  // your own logic here
}
(function ($) {
    var oldGetEditor = $.fn.getEditor;
    $.fn.getEditor = function() {

       //you can call the oldGetEditor here if you want
    };
})(jQuery);