background preloader

Javascript / Patterns

Facebook Twitter

Functional Programming in Javascript. Functional programming provides developers with the tools to abstract common collection operations into reusable, composable building blocks.

Functional Programming in Javascript

You'll be surprised to learn that most of the operations you perform on collections can be accomplished with five simple functions: map filter mergeAll reduce zip Here's my promise to you: if you learn these 5 functions your code will become shorter, more self-descriptive, and more durable. Also, for reasons that might not be obvious right now, you'll learn that these five functions hold the key to simplifying asynchronous programming. Once you've finished this tutorial you'll also have all the tools you need to easily avoid race conditions, propagate and handle asynchronous errors, and sequence events and AJAX requests. Finishing the Interactive Exercises This isn't just a tutorial, it's a series of interactive exercises that you can fill out right in your browser! JavaScript Patterns. JSComplexity.org. Eloquent JavaScript: A Modern Introduction to Programming.

Closure Compiler Service. Closure-compiler - Closure Compiler. Closure Compiler Closure Compiler is a JavaScript optimizing compiler.

closure-compiler - Closure Compiler

It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. It is used in many of Google's JavaScript apps, including Gmail, Google Web Search, Google Maps, and Google Docs. Try it out! It's easy to try the compiler through our web application at Get the Compiler Download the compiler at or using Maven.

The zip file contains a README with quick instructions to get you started. User Documentation You can read more about Closure Compiler at We also have a few low-key wiki pages at Please suggest new ones if you see anything missing. Developer Documentation The Closure Compiler javadocs are available at You can browse the source at We accept patches :) ECMAScript 5 Strict Mode, JSON, and More. Previously I analyzed ECMAScript 5’s Object and Property system.

ECMAScript 5 Strict Mode, JSON, and More

This is a huge new aspect of the language and deserved its special consideration. There are a number of other new features and APIs that need attention, as well. The largest of which are Strict Mode and native JSON support. Strict Mode Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a “strict” operating context. Jslibraryboilerplate by dciccale. An easy boilerplate for rolling your own JavaScript Library like jQuery, Zepto, Prototype, etc.

jslibraryboilerplate by dciccale

The code is written in CoffeeScript, TypeScript and pure JavaScript. Skip this if you want to use pure JavaScript version. Prototypal Inheritance. Douglas Crockford www.crockford.com Five years ago I wrote Classical Inheritance in JavaScript (Chinese Italian Japanese).

Prototypal Inheritance

It showed that JavaScript is a class-free, prototypal language, and that it has sufficient expressive power to simulate a classical system. My programming style has evolved since then, as any good programmer's should. I have learned to fully embrace prototypalism, and have liberated myself from the confines of the classical model. My journey was circuitous because JavaScript itself is conflicted about its prototypal nature. Prototype-based programming. A fruit bowl serves as one example.

Prototype-based programming

A "fruit" object would represent the properties and functionality of fruit in general. A "banana" object would be cloned from the "fruit" object, and would also be extended to include general properties specific to bananas. Each individual "banana" object would be cloned from the generic "banana" object. Design and implementation[edit] Prototypal inheritance in JavaScript is described by Douglas Crockford as: you make prototype objects, and then ... make new instances.

Almost all prototype-based systems are based on interpreted and dynamically typed languages. Object construction[edit] Systems that support ex nihilo object creation allow new objects to be created from scratch without cloning from an existing prototype. This example in JS 1.8.5 + ( see ) Delegation[edit] Concatenation[edit] The main conceptual difference under this arrangement is that changes made to a prototype object are not automatically propagated to clones. Criticism[edit] Top Down Operator Precedence. Douglas Crockford Introduction Vaughan Pratt presented "Top Down Operator Precedence" at the first annual Principles of Programming Languages Symposium in Boston in 1973.

Top Down Operator Precedence

In the paper Pratt described a parsing technique that combines the best properties of Recursive Descent and Floyd's Operator Precedence. Valid JavaScript variable names. Did you know var π = Math.PI; is syntactically valid JavaScript?

Valid JavaScript variable names

I thought this was pretty cool, so I decided to look into which Unicode glyphs are allowed in JavaScript variable names, or identifiers as the ECMAScript specification calls them. Reserved words The ECMAScript 5.1 spec says: An Identifier is an IdentifierName that is not a ReservedWord. The spec describes four groups of reserved words: keywords, future reserved words, null literals and boolean literals. JavaScript variable name validator. Wondering if you can use a given string as a variable name in JavaScript?

JavaScript variable name validator

Learn how it works, or just use this tool. <strong>To use this tool, please <a href= JavaScript</a> and reload the page. </strong> permalink That’s a valid identifier according to ECMAScript 5.1 / Unicode 6.2. However, the NaN, Infinity, and undefined properties of the global object are immutable or read-only. Rwldrn/idiomatic.js.