Extending an Existing Javascript Function

Extending an existing javascript function

This is how you extend an existing javascript function.
Assuming that you want to preserve the existing function and the “added algorithm” is somewhat only needed to be executed based on a certain environment only.


1
2
3
4
5
6
7
8
9
10
11
12
function abc(){
  alert('abc is called');      
}      
var abcOrig = abc;
abc = function(){
  abcOrig();
  alert('abc has been extended!');
}
alert('test 1');
abc();
alert('test 2');
abc();
This entry was posted in javascript, Web Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


five + 6 =