Index ¦ Archives ¦ Atom

Javascript - Crockford On JS Act III

Just some gleaned insights taken from Douglas Crockford's Act III presentation on Javascript. You'll likely want to watch the video to understand why these things are important.

  1. Declare all variables at the top of a function.
  2. Declare all functions before you call them.
  3. Treat arguments as read-only.
  4. this is available to an inner function through assigning the outer this to another variable.
  5. apply and call can specify what this refers to.
  6. function => this is global object or undefined, method => this is the object calling the method, constructor => this is the new object, apply/call => this is passed in as an argument.
  7. Promise making is queuing up calls to happen when something happens that is likely asynchronous.
  8. Don't make functions in a loop.
  9. Y Combinator - mind is now blown.

"[Closure] is one of the most important features in javascript."

"[Closure] is the thing that makes javascript one of the world's brilliant programming languages."

Y Combinator

function y(le) {
return (function (f) {
return f(f);
}(function (f) {
    return le(function (x) {
        return f(f)(x);

var factorial = y(function (fac) {
     return function (n) {
         return n <= 2 ? n : n * fac(n - 1);

var number120 = factorial(5);

© Steve Spigarelli. Built using Pelican. Theme by Giulio Fidente on github.