Linked Questions
69 questions linked to/from Why do you need to invoke an anonymous function on the same line?
44 votes
4 answers
2k views
Explain the following JavaScript statement? [duplicate]
var ninja = (function(){ function Ninja(){}; return new Ninja(); })(); Why is the function above encapsulated in parentheses and why is there a (); at the end? I think it's a constructor ...
3 votes
3 answers
655 views
JavaScript Functions that return function [duplicate]
I was solving a puzzle on JS and I found this code: var xx = (function () { var e = 0; return function () { return e++ } })(); It was asked what will be the value of xx. I've googled about ...
3 votes
2 answers
185 views
(function(){})() Is there any documentation of this? [duplicate]
Possible Duplicate: How does an anonymous function in JavaScript work? What does this JavaScript snippet mean? I use in my scripts: (function(){ ...[code].. })() I can't find documentation ...
-4 votes
2 answers
193 views
how does javascript !function() { } work [duplicate]
How does this structure work when the function is anonymous? !function() { . . . }();
2 votes
1 answer
161 views
javascript syntax explanation (function () { } )(); [duplicate]
i see the following code in a lot of java-script files. (function () { //code goes here })(); Can somebody explain this, or point me to a tutorial that explains this?
-1 votes
1 answer
122 views
Anonymous Function + javaScript [duplicate]
How it is work? function(){...}(); I can't understand what's going on. I think this is javascript not node.js puzzle. But I can not find solution. fs.readdir(filesDir, function(err, files) { if (err)...
0 votes
0 answers
83 views
JavaScript: What is an anonymous function? [duplicate]
I have these few lines of code: (function(exports){ // Do something })(typeof exports===typeof {}&&exports===this?exports:this.webdriver=this.webdriver||{}) What does this mean? How can I ...
1 vote
0 answers
30 views
javascript auto execute anonymous function - parenthesis [duplicate]
What is - if there is any - the difference between these two pieces of code: (function(){ // code }); AND (function(){ // code })();
1082 votes
29 answers
651k views
How do I declare a namespace in JavaScript?
How do I create a namespace in JavaScript so that my objects and functions aren't overwritten by other same-named objects and functions? I've used the following: if (Foo == null || typeof(Foo) != "...
322 votes
7 answers
136k views
What do parentheses surrounding an object/function/class declaration mean? [duplicate]
In the YUI library examples, you can find many uses of this construct: (function() { var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, layout = null, ... })(); I think the last ...
44 votes
11 answers
129k views
JavaScript Infinitely Looping slideshow with delays?
How do I make an infinite loop in JavaScript? I'm trying to make a slideshow, which I have working, but I can't get it to loop. I can't even get it to loop twice. The code I'm using right now is ...
65 votes
4 answers
30k views
JavaScript anonymous function immediate invocation/execution (expression vs. declaration) [duplicate]
Possible Duplicates: What is the difference between a function expression vs declaration in JavaScript? Explain JavaScript's encapsulated anonymous function syntax Why this: (function () { ...
12 votes
4 answers
16k views
jQuery and $ questions
I am modifying some code that has a lot of jQuery but I am not sure what some of the jQuery statements are doing. At the top of the jQuery code there is jQuery.noConflict *1. I understand that. But ...
50 votes
1 answer
33k views
Javascript Function Definition Syntax [duplicate]
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} Declaring functions in JavaScript I've seen 2 different syntaxes for defining functions in ...
43 votes
2 answers
40k views
Difference between function with a name and function without name in Javascript
1. function abc(){ alert("named function"); } v/s 2. function(){ alert("Un-Named function"); } Kindly explain from beginners point.