问题
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