1
vote
0answers
68 views

JS closures - Passing a function to a child, how should the shared object be accessed

I have a design and am wondering what the appropriate way to access variables is. I'll demonstrate with this example since I can't seem to describe it better than the title. Term is an object ...
0
votes
1answer
98 views

what does it mean when a nested function isn't assigned to a var?

I'm referencing this link about closures: http://stackoverflow.com/questions/111102/how-do-javascript-closures-work This is specifically about javascript. In the second answer with 956 votes, The ...
1
vote
1answer
906 views

Javascript idioms this that vs this self [closed]

I've been writing JavaScript for a bit and have now seen code using the idiom var that = this; and var self = this; Used to gain access to this through closure scope. At this point var self = ...
0
votes
4answers
1k views

What's so useful about closures (in JS)? [duplicate]

In my quest to understand closures in the context of JS, I find myself asking why do you even need to use closures? What's so great about having an inner function be able to access the parent ...
1
vote
1answer
338 views

Make a flowchart to demonstrate closure behavior

I saw below test question the other day in which the authors used a flowchart to represent the logic of loops, and I got to thinking it would be interesting to do this with some more complex logic. ...
3
votes
1answer
211 views

What is the proper jargon to refer to a variable wrapped inside a function closure?

In JavaScript, there is no such thing as a "private" variable. In order to achieve encapsulation and information hiding in JavaScript, I can wrap a variable inside a function closure, like so: var ...
3
votes
2answers
338 views

Why to keep wrapping closure in each js-file if it can be added after concatenating?

At the moment every javasrcipt file in our project includes closure wrapper. Before deploying all files are concatenated and minimized. And i'm asking myself, do we really need all that closures OR ...
2
votes
2answers
166 views

Trimming script size by using array notation for frequently accessed properties

I noticed some redundancy in a script I ran through Google Closure Compiler. (function(){function g(a){var k;if(a){if(a.call)a.prototype=j,a.prototype[e]={}}else a= {};var ...
7
votes
3answers
900 views

What common programming problems are best solved by using prototypes and closures?

As much as I understand both concepts, I can't see how can I take advantage of JavaScript's closures and prototypes aside from using them for creating instantiable and/or encapsulated class-like ...
14
votes
7answers
2k views

Why is closure important for JavaScript?

C#'s lambda expression also has closures but is rarely discussed by the C# communities or books. I see far more JavaScript people and books talk about its closures than they do in the C# world. Why is ...
2
votes
3answers
344 views

How to avoid shooting yourself in the foot when using closure in JavaScript

The closure feature is widely used in JavaScript and make it quite difficult for programmer who was used to program in a no-closure language. So what is the best practice about using closure and how ...