Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying PHP Ajax Cookbook
  • Table Of Contents Toc
PHP Ajax Cookbook

PHP Ajax Cookbook

4 (5)
close
close
PHP Ajax Cookbook

PHP Ajax Cookbook

4 (5)

Overview of this book

Table of Contents (16 chapters)
close
close
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1
Index

Using the anonymous function of JavaScript


The Anonymous function of JavaScript is very useful for avoiding conflicts in the JavaScript library.

How to do it...

Let's first understand the Anonymous function with an example:

(function(msg) 
    { alert(msg); })
('Hello world');

When we execute the preceding code in a browser, it will display the alert Hello world. Now, that's interesting! A function is defined and also executed! Let's simplify the same code snippet and see how it works:

Var t = function(msg){
  alert(msg);
};
t('Hello world');

If you see the equivalent code, it's straightforward. The only difference is that this simplified code has the variable name t associated with the function while, in the other code, the function name is anonymous. The Anonymous function gets executed instantly after declaring it.

Anonymous functions are very useful while creating the plugins of JavaScript frameworks, as you don't have to worry about conflicts with other plugins that have the same name as...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
PHP Ajax Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon