Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 6th, 2011, 03:08 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default what is the meaning of (function(a){...})(window);

Hello,
somewhere i've seen this type of javascript codes:


Code:
(function(a){
// some code here ...
})(window);

or

(function(){
// some code here ...
})(jQuery);

or

(function(){
//some code here...
})();
what does these codes do?
Reply With Quote
  #2 (permalink)  
Old November 9th, 2011, 01:19 PM
Friend of Wrox
Points: 742, Level: 10
Points: 742, Level: 10 Points: 742, Level: 10 Points: 742, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2009
Location: Tehran, Iran
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default The answer

Hello,
I myself found the answer.
these are some ways to write less code. as you know the next line refers to a function:
Code:
function x(arg){ /*some codes here ...*/ }
what about this: ?
Code:
(function x(arg){ /*some codes here ...*/ })
we can call a function by passing parameters like:
Code:
x(3);
so ...
Code:
(function (a){ /* ... */ })(window);
means passing 'window' object as parameter 'a' to the defined function. in the body of this function , 'a' points to 'window'
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Call function from window.showModalDialog vinod_yadav1919 Javascript 0 May 6th, 2008 09:27 AM
meaning post and get amged Pro PHP 1 August 1st, 2007 06:33 AM
meaning of a warning mastrgamr C++ Programming 7 December 22nd, 2006 07:16 AM
how can i call hook function to a specified window pradpb999 Access 0 December 30th, 2005 12:34 AM
Meaning mani_he Beginning PHP 3 January 18th, 2005 11:26 PM



All times are GMT -4. The time now is 09:32 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.