Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2011, 04:08 PM
Friend of Wrox
 
Join Date: Nov 2009
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?
 
Old November 9th, 2011, 02:19 PM
Friend of Wrox
 
Join Date: Nov 2009
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'





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 08:16 AM
how can i call hook function to a specified window pradpb999 Access 0 December 30th, 2005 01:34 AM
Meaning mani_he Beginning PHP 3 January 19th, 2005 12:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.