Alister West

home is where your code is ...

Javascript Basics

Regex's

// Match a label and assiciated id
var input = 'Address Name<span class="postcode">R2D2J1</span>'; 
var matches = input.match(/^([^<]+)<span class=['"]postcode['"]>([^<]+)<\/span>/);
console.log( matches ); // [1,2] are the captures

Objects

// Everything in JS is an Object
// In js scope/encapsulation is bounded by functions we start with a function.
var Pie = function () {
    this.foods = [];
}
Pie.prototype.add( stuff ) {
    if (stuff.constructor == Array) {
        this.foods.concat( stuff );
    }
    else {
        this.foods.push( stuff );
    }
    return this; // for chaining goodness
}

Namespaces

// Wrap you objects in a variables scope to give them a namespace.

// .. my_module.js ..
var my_module_ns = my_module_ns || {}; // don't clobber.
my_module_ns.Pie = function () { this.foods = []; return this; }

// main.js
var pie = new my_module_ns.Pie(); // ..
By Alister West