Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thanks! Awesome group. I put out a simple question in the access/vba forum that I couldn't find answered on technet or anywhere else on the web and it was answered the same day!!..."

Geography

Where in the world do Tek-Tips members come from?

Reasoning behind nameless functions

xwb (Programmer)
24 Jul 12 0:31
This is becoming more common in a lot of code on the internet: something called immediately invoked function expression

CODE --> IIFE

// some code
(function(){
   //do some work 
})();
// more code 

The bit I don't understand it why people do that instead of just

CODE --> IIFE

// some code
// do some work
// more code 
It is actually 2 lines less. Also why do so many coders use inline variable assignments to function expressions. Why not just declare the function first and then call it like in any other language. Instead of

CODE --> simple

// function decl
// some code
x = decl(...)
// more code 
we get

CODE --> decl

// some code
x = (function (...) {
   // function body
   } (...)
// more code 
It is actually more difficult to read because you cannot see the flow so easily as it is obscured by the function body (which can be pretty big).

What is the reasoning behind IIFE other than making code difficult to read, decipher and maintain?
feherke (Programmer)
24 Jul 12 2:08
Hi

Closures. Something like namespaces in other languages.

Feherke.
http://feherke.github.com/

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close