Skip to content

Instantly share code, notes, and snippets.

@zealoushacker
Created December 23, 2013 04:24
Show Gist options
  • Select an option

  • Save zealoushacker/8091614 to your computer and use it in GitHub Desktop.

Select an option

Save zealoushacker/8091614 to your computer and use it in GitHub Desktop.
A closure containing a pure function in js
/*
Functions containing no free/unbound variables are called pure functions.
Functions containing one or more free variables are called closures.
Adapted from the quick exercise in https://leanpub.com/javascript-allonge/read#closures
If pure functions can contain closures, can a closure contain a pure function?
Attempt to compose a closure that contains a pure function.
Many thanks to @raganwald!
*/
(
function (x) {
return function (y) {
(function (n) {
return n;
});
return x;
};
}
)("foo")("bar");
//=> 'foo'
@zealoushacker
Copy link
Author

@raganwald What do you think about this as an example of pure functions contained in closures? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment