javaScript function overloading part -1

Classical (non-js) approach to overloading:
function myFunc(){

function myFunc(overloaded){
//other code
Javascript wont let more than one function be defined with the same name.
In javascript, same named functions automatically override earlier functions with the exact same name.
So, you can’t call the first one.
Try it:
function a() {alert(1);}
function a() {alert(2);}
a(); // alerts ‘2’

The first function declaration is always overwritten by the second, regardless of the condition.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s