overriding a function defined in jquery closure

浪子不回头ぞ 提交于 2020-01-02 07:29:26

问题


I have a function defined in jquery closure and called by another function in the same closure. Could I override the function being called without changing the closure itself. See the code for example

(function($){
    function Myfunction(value)
    {
        //do something with the value
    }
    $('a').live('click',function(){
        MyFunction($(this).val())
    });
}(JQuery));

is there a way I can override Myfunction so that overriden copy of Myfuntion is called inside event handler.


回答1:


You can't. Functions defined inside closures are private - and they:

[cannot] be accessed directly from outside the anonymous function




回答2:


Writing function f() {} does several things with the function (although I wouldn't have guessed that keeping it out of the namespace was one of them). Writing var f = function() { } treats f as an ordinary variable.



来源:https://stackoverflow.com/questions/6229501/overriding-a-function-defined-in-jquery-closure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!