Invoke Two Functions With The Same Name
In short i want to overwrite a javascript function with a newer one, but in that newer function i want to be able to call the old one. So for example: function test() { alert('
Solution 1:
function test()
{
console.log('original');
}
var test = function (oldFn) {
// /\
// -------
// \/
return function () { // <- return a new function which will get stored in `test`
oldFn(); // use the passed `oldFn`
console.log('new function'); // the new code
};
}(test); // <- pass in the old function, we do this, to avoid reference problems
// call function
test();
Solution 2:
Why don't you create a new function
and put inside the function test()
so that when the function test()
is called then the new function
is called too..
e.g.
function test(){
//code
your_new_function();
}
function your_new_function(){
//code
}
Solution 3:
Use below instead of making same name function
$(document).ajaxComplete(function() {
// do your work
});
You can't create two functions of same name
Post a Comment for "Invoke Two Functions With The Same Name"