Last active
August 29, 2015 13:57
-
-
Save Agnostic/9895928 to your computer and use it in GitHub Desktop.
Who called me?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is very common in big projects with a lot of scripts, | |
// when the programmer doesn't know where a function/action was called | |
// Assigning a reference | |
$.fn.val2 = $.fn.val; | |
// Overwriting the original function | |
$.fn.val = function(){ | |
console.log( this, arguments ); | |
console.log( 'Called from: ', arguments.callee.caller ); | |
// Calling the original function to keep the flow | |
return $.fn.val2.apply(this, arguments); | |
}; | |
// Example: | |
var myMethod = function(){ | |
$('input:eq(0)').val(1); | |
}; | |
myMethod(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment