5

This is default for all 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'
    });

Now I am writing another js. I need to override the getEditor in my js...

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
user2819086
  • 51
  • 1
  • 1
  • 2

3 Answers3

9

You haven't described your question, clearly but based on what you have mentioned in the title:

override the existing function in jquery

It seems you want to change a jQuery function and they usually are defined like $.fn.getEditor if it is the case, you should do:

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

       //you can call the oldGetEditor here if you want
    };
})(jQuery);
Mehran Hatami
  • 12,723
  • 6
  • 28
  • 35
0

You simply get a reference to the function "getEditor" and assign it another function.

getEditor:function(){
// new function will override the existing reference that getEditor already has.
}
Vasile
  • 134
  • 2
0
someObject = {
 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'
  });
}

So just write

someObject.getEditor = function(){
  // your own logic here
}

You must get object where getEditor function stored, and use reference to change it.

Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37