Simon Willison’s Weblog

Subscribe
Atom feed for closures

22 posts tagged “closures”

2013

What are some JavaScript concepts that took you the longest to understand?

Closures, prototype inheritance, and the “this” keyword.

[... 60 words]

2009

10 Uses for Blocks in C/Objective-C. Part of the Cocoa for Scientists series, which is by far the best free Objective-C / Cocoa tutorial I’ve seen anywhere.

# 16th November 2009, 2:27 pm / cocoa, osx, objectivec, blocks, closures, science

And so it goes, around again. Charles Miller on Java, pointing out that if you don’t have closures and first-class functions you end up having to add band-aid solutions and special case syntactic sugar. Python’s lack of multi-line lambdas leads to a similar (though less pronounced) effect.

# 3rd September 2009, 9:46 am / java, python, charles-miller, programming-languages, closures

Mac OS X 10.6 Snow Leopard: the Ars Technica review. The essential review: 23 pages of information-dense but readable goodness. Pretty much everything I know about Mac OS X internals I learnt from reading John Siracusa’s reviews—this one is particularly juice when it gets to Grand Central Dispatch and blocks (aka closures) in C and Objective-C.

# 1st September 2009, 7:05 pm / objectivec, c, closures, blocks, osx, apple, john-siracusa, grandcentraldispatch, snowleopard

Why I don’t love JavaScript’s Module Pattern. Jonathan Snook points out that the module pattern (where private functionality is hidden in a closure and only public methods are revealed to outside scopes) makes code a lot harder to debug. I use the module pattern for pretty much everything, not because I want to keep stuff private but more to avoid any chance of leaking out in to the global namespace. If I need to debug a value I temporarily assign it as a property on the global window object.

# 30th April 2009, 7:59 pm / javascript, modulepattern, jonathan-snook, closures, debugging

why’s potion. why’s latest project is a small, fast language (JIT to x86/x86-64) which seems to take ideas from Ruby, Lua, Python and who knows where else. Everything is based around objects, closures and mixins, with the delightful inclusion of scoped mixins so you can modify an object only within a certain module (hence avoiding Ruby’s action-at-a-distance problems).

# 8th January 2009, 6:37 pm / ruby, whytheluckystiff, potion, programming, languages, jit, lua, mixins, closures

2008

Blocks in Objective-C. Closures are coming soon to Objective-C - interesting syntax, a regular curly brace block preceded by a caret ^{ ... }.

# 29th December 2008, 7:38 pm / objectivec, closures, programming, blocks, syntax

php: rfc: closures (via) I never thought I’d see the day, but a patch adding closures to PHP has been both proposed and accepted! Looks like a solid implementation—the syntax is similar to JavaScript but makes explicit which variables are to be captured. As with much of PHP, values are copied in to the closure by default but you can use an ampersand to specify JavaScript-style pass-by-reference instead.

# 19th July 2008, 10:58 pm / closures, php, functional-programming, javascript

Module Pattern Provides No Privacy... at least not in JavaScript(TM) (via) JavaScript variables hidden inside a closure aren’t as hidden as I thought—it turns out you can pass a closure as the second argument to eval (at least in Firefox) and “steal” private variables back out of it.

# 27th June 2008, 7:01 pm / closures, javascript, firefox, modulepattern, pete-michaux

2007

IE JScript Performance Recommendations Part 3. Once again, Microsoft’s official advice is to avoid closures entirely rather than learn how to use them safely. Sigh.

# 9th January 2007, 11:48 am / microsoft, ie, closures, javascript

2006

JavaScript Closures for Dummies. Not quite for Dummies as it talks about C pointers, but a valiant attempt.

# 6th July 2006, 10:01 am / closures

Getting Funky With Scopes and Closures. Mark Wubben has some neat tricks up his sleeve.

# 23rd January 2006, 10:27 am / closures

2005

Leak Free Javascript Closures. This is some pretty brilliant JavaScript voodoo.

# 27th October 2005, 1:52 pm / closures

Another practical use for JavaScript closures. Create private methods by hiding them in a closure.

# 31st July 2005, 1:08 pm / closures

2004

Martin Fowler on Closures. They really aren’t that complicated once they’re explained well.

# 9th September 2004, 7:51 am / martin-fowler, closures

XMLHttpRequest and Javascript Closures. Harry gets intimate with Mozilla’s XMLHttpRequest object.

# 27th May 2004, 12:23 am / closures

Closures and executing JavaScript on page load. I’ve tried to explain closures on my SitePoint blog, using addLoadEvent() as an example.

# 26th May 2004, 7:09 am / closures

Executing JavaScript on page load

Peter-Paul Koch recently wrote:

[... 772 words]

Groovy: Closures. I’d nearly written Groovy off as a pointless Jython clone, but it actually has some interesting features.

# 11th April 2004, 8:01 am / closures

2003

Closures and continuations

Thanks to Dan Sugalski (designer of Parrot, the next generation Perl VM) I finally understand what continuations and closures actually are. He explains them as part of a comparison between the forthcoming Parrot and two popular virtual machines already in existence: