logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-15-2011, 08:19 PM   #1
Adam_C
 
Join Date: Feb 2009
Posts: 129
Question self executing functions

Hi,

I've recently come across the code
Code:
(function(){
//...Code here
})
What is the difference with wrapping your code with this, rather than just writing it in the script tags...?
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 03-16-2011, 12:14 AM   #2
DWcourse
DWcourse's Avatar
 
Join Date: Apr 2009
Posts: 3,276
Default

was this on a php page or perhaps inside a script?
__________________
If my answer helped, check out DWcourse.com for Dreamweaver tips and tutorials.
DWcourse is offline   Reply With Quote
Old 03-16-2011, 01:23 PM   #3
Adam_C
 
Join Date: Feb 2009
Posts: 129
Default

I saw it inside JS
__________________
http://adamscarter.co.uk/
Adam_C is offline   Reply With Quote
Old 03-16-2011, 02:13 PM   #4
DWcourse
DWcourse's Avatar
 
Join Date: Apr 2009
Posts: 3,276
Default

the script tags wrap the javascript code (or the link to the javascript file). This is actually defining a function that can then be used somewhere else.
__________________
If my answer helped, check out DWcourse.com for Dreamweaver tips and tutorials.
DWcourse is offline   Reply With Quote
Old 03-16-2011, 08:42 PM   #5
ranjan
 
Join Date: Dec 2004
Posts: 405
Default

the code would have been

Code:
(function(){
//...Code here
})();
These are called self executing functions or self invoking functions

http://briancrescimanno.com/2009/09/...unctions-work/
ranjan is offline   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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:01 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com