Based on Simon Willison's original 2005 eTech talk, Simon expands this into a full article covering the expressive functionality of JavaScript. He covers the basics of JavaScript: literals, variables, functions, scope, control flow, objects, classes, inner functions and closures. Everything a developer needs to know before diving into more advanced JavaScript.
Cory Hudson sees callbacks as benefiting from currying JavaScript functions, and defines currying as turning a function with two arguments into a function with one argument that returns a function of one argument. He starts off with two functions and shows how to combine them into one curried function, and also builds a generic version. He shows a good usage of a curried function in an array map()
function, which is similar to Prototype's bind()
.
Erik Arvidsson warns against extending the JavaScript Object with Object.prototype, as it can lead to breakages in third party code when they use the for(key in obj) method of iterating through any class (since they all are subclasses of Object). Instead Erik recommends extending the classes that directly benefit from the extending functions, and treat Object as a final constant. Erik also suggests that hashes and associative arrays should be done in JavaScript using Object, not Arrays.