Skip to content

Instantly share code, notes, and snippets.

@Agnostic
Last active August 29, 2015 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Agnostic/9895928 to your computer and use it in GitHub Desktop.
Save Agnostic/9895928 to your computer and use it in GitHub Desktop.
Who called me?
// 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