Skip navigation

While surfing through internet I came across one interesting JavaScript technic. Just observe the code snippet below

// self redefining function
var myFunction = function () {
    //set up code only to this once
    alert("set up, only called once");

    // set up code now complete.
    // redefine function so that set up code is not re-executed
    myFunction = function() {
        alert("no set up code");
    }
}
myFunction(); // outputs - Set up, only called once
myFunction(); // outputs - no set up code this time
myFunction(); // outputs - no set up code this time 
// 

In practical scenario we can use it intelligently. What do you say??? 🙂

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: