开发者

How to extend this jQuery function

I want to extend this function and make my own, this new function should have same functions as the old one but additionalOkClicked should be overwritten with my own function.

How do I do this?

   (function ($) {
    $.LocationDialog = {
        mainInit: function()
        {
            //some code here
        },

        init: function(callingNum)
        {
            //some code here
        },

        additionalOkClicked: 开发者_如何学JAVAfunction()
        {
            //i want to override this function
        }
    };
})(jQuery);


can't you just do:

$.LocationDialog.myAdditionalOnClick = function()
{
    this.additionalOnClick(); //call the other method in the object.
}

if y our talking about the function being bound to an event then use:

$('#foo').unbind('click',$.LocationDialog.additionalOnClick);
$('#foo').bind('click',$.LocationDialog.myAdditionalOnClick);


You can just add code to delete that function and then create your own with the same name:

(function ($) {
  delete $.LocationDialog.additionalOkClicked;

  $.LocationDialog.additionalOkClicked = function () {
    // your code here
  };
})(jQuery);

The rest of $.LocationDialog object will remain the same.


Use prototype:

$.locationDialog.prototype.functionName = function() {
    // Your code here
}

or

$.locationDialog.additionalOkClicked.prototype.functionName = function() {
    // Code here
}

or just create another function inside of $.locationDialog:

   (function ($) {
    $.LocationDialog = {
        mainInit: function()
        {
            //some code here
        },

        init: function(callingNum)
        {
            //some code here
        },

        additionalOkClicked: function()
        {
            //some code here
        }

        functionName: function() {
            // Your code here
        }
    };
})(jQuery);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜