开发者

overriding a function defined in jquery closure

开发者 https://www.devze.com 2023-03-11 09:25 出处:网络
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

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.


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

[cannot] be accessed directly from outside the anonymous function


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.

0

精彩评论

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