Joined July 2013
·

Paul van Zyl

CTO, Senior Developer at Nona Creative
·
Cape Town
·
·
·

nice one, not exactly what I was looking for but pretty damn close and its nice to know that backbones pretty flexible when it comes to this sort of thing.

Posted to BackboneJS: On vs. Bind vs. listenTo over 1 year ago

nice. - thanks for the tip.

Posted to Eureka! I finally understand closures over 1 year ago

Okay, did some googling (I cannot recall the number of times I looked this up casually), I found the following, which - armed with your example (and maybe some more experience), made a lot more sense :

http://www.jibbering.com/faq/faq_notes/closures.html

A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).

The simple explanation of a Closure is that ECMAScript allows inner functions; function definitions and function expressions that are inside the function bodes of other functions. And that those inner functions are allowed access to all of the local variables, parameters and declared inner functions within their outer function(s). A closure is formed when one of those inner functions is made accessible outside of the function in which it was contained, so that it may be executed after the outer function has returned. At which point it still has access to the local variables, parameters and inner function declarations of its outer function. Those local variables, parameter and function declarations (initially) have the values that they had when the outer function returned and may be interacted with by the inner function.

This stack overflow thread was super helpful.

http://stackoverflow.com/questions/1801957/what-exactly-does-closure-refer-to-in-javascript

Posted to Eureka! I finally understand closures over 1 year ago

okay, so I understand the example you've given but I'm still not 100% clear about the what and why of closures. I feel like there are two aspects to my "mental fog" around this, and maybe you can help.

1) Definition of a closure : a function inside a function (?) that operates on the original function output(?), as kind of a secondary process, and in your example seems to accept its own arguments (? - I assume not always ?)
2) Can you illustrate a more "real world" use case ? explaining why one would choose to use a closure (?)

Achievements
14 Karma
262 Total ProTip Views