Thinking functionally 3 Function composition 4 Function decomposition 5 Decorators 6 Further reading Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 5 / 37
Less Identities Applying Returns Call by value, call by reference Closures, scope, & environments Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 7 / 37
function (diameter) { return diameter * Pi } Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 8 / 37
argument with the name you want: (function (Pi) { return function (diameter) { return diameter * Pi } })(3.14159265) Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 9 / 37
input and returns output No effect on other objects or states Contains no free variables Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 11 / 37
Thinking functionally 3 Function composition 4 Function decomposition 5 Decorators 6 Further reading Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 12 / 37
’ apple ’, ’ pear ’]; var result = []; for (var i = 0; i < fruit.length; i++) { result.push(fruit[i].trim()); } Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 14 / 37
’ apple ’, ’ pear ’]; var result = fruit.map(function(val) { return val.trim(); }); Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 15 / 37
’ apple ’, ’ pear ’]; var result = fruit.map(globalize(’trim’)); Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 16 / 37
Thinking functionally 3 Function composition 4 Function decomposition 5 Decorators 6 Further reading Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 19 / 37
... } var post = applyLeft(xhr, ’POST’); var get = applyLeft(xhr, ’GET’); Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 20 / 37
functionally 3 Function composition 4 Function decomposition 5 Decorators 6 Further reading Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 27 / 37
function, and the returned function is a variation of the argument function. Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 28 / 37
Lisp Flavors before after around provided Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 30 / 37
Thinking functionally 3 Function composition 4 Function decomposition 5 Decorators 6 Further reading Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 32 / 37
is why we have Java. The joy of JavaScript is rooted in its lack of rigity and the infinite possibilities that this allows for.” —Angus Croll Seth House <[email protected]> (Utah JS) Functions, combinators, and decorators in JavaScript 2013-02-19 34 / 37