Skip to content

Instantly share code, notes, and snippets.

/*!
* jQuery Tiny Pub/Sub for jQuery 1.7 - v0.1 - 27/10/2011
* Based on @cowboy Ben Alman's REALLY tiny pub/sub.
* 1.7 specific updates by @addyosmani.
* Copyright maintained by @cowboy.
* Dual licensed under the MIT and GPL licenses.
*/
(function($){
/*
* memoize.js
* by @philogb and @addyosmani
* further optimizations by @mathias
* Released under an MIT license.
*/
function memoize( fn ) {
return function () {
var args = Array.prototype.slice.call(arguments),
hash = "",

The dictionary refers to a Mediator as 'a neutral party who assists in negotiations and conflict resolution'.

In software engineering, a Mediator is a behavioural design pattern that allow us to expose a unified interface through which the different parts of a system may communicate. If it appears a system may have too many direct relationships between modules, it may be time to have a central point of control that modules communicate through instead. The Mediator promotes loose coupling by ensuring that instead of modules referring to each other explicitly, their interaction is handled through this central point.

If you would prefer an analogy, consider a typical airport traffic control system. A tower (Mediator) handles what planes (modules) can take off and land because all communications are done from the planes to the control tower, rather than from plane-to-plane. A centralized controller is key to the success of this system and that's really the role a mediator plays in software design.

In real-worl

#Building RESTful applications with Backbone

In this section of the book, we're going to take a look at developing RESTful applications using Backbone.js and modern technology stacks. When the data for your back-end is exposed through a purely RESTful API, tasks such as retrieving (GET), creating (POST), updating (PUT) and deleting (DELETE) models are made easy through Backbone's Model API. This API is so intuitive in fact that switching from storing records in a local data-store (e.g localStorage) to a database/noSQL data-store is a lot simpler than you may think.

##Stack 1: Using Node.js, Express, Mongoose and MongoDB

The first stack we'll be looking at is:

/*
* documentReady.js - a cross-browser jQuery core based DOMContentLoaded solution
* Released under an MIT license
* Portions: jQuery project, Diego Perini, Lucent M.
* This version: Addy Osmani, 2012
*/
/*
* Usage:
documentReady(function(){
@ravitb
ravitb / async.js
Created August 30, 2013 03:12 — forked from addyosmani/async.js
// some modified async work based on prior by necolas
(function(d){
var js,
fjs = d.getElementsByTagName('script')[0],
frag = d.createDocumentFragment(),
add = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement('script');
js.src = url;
id && (js.id = id);

When we put up a facade, we present an outward appearance to the world which may conceal a very different reality. This was the inspiration for the name behind the next pattern we're going to review - the facade pattern. The facade pattern provides a convenient higher-level interface to a larger body of code, hiding its true underlying complexity. Think of it as simplifying the API being presented to other developers, something which almost always improves usability.

Facades are a structural pattern which can often be seen in JavaScript libraries like jQuery where, although an implementation may support methods with a wide range of behaviors, only a 'facade' or limited abstraction of these methods is presented to the public for use.

This allows us to interact with the facade rather than the subsystem behind the scenes. Whenever you're using jQuery's $(el).css() or $(el).animate() methods, you're actually using a facade - the simpler public interface that avoids you having to manually call the ma