Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A view model for CoffeeScript in the browser.
JavaScript CoffeeScript CSS


Uniform is a way of organising your front-end CoffeeScript or JavaScript. You describe individual components of your application as Uniform classes. They can be used for delegating events, describing behaviour and handle the building of elements.

For example a contact form could have AJAX behaviour described as a Uniform class.

# Let's describe a contact form
class ContactForm extends Uniform

  # The HTML template
  template: (built) -> built """

  # We cache some children to properties on this object
  elements: (add) ->
    add('msg', 'textarea')
    add('btn', 'button')

  # We delegate the submit event to @sendResponse()
  events: (add) ->
    # attach submit event to @el
    add 'submit', (el, e) ->

  # Do the sending :)
  send_response: ->
    $.post 'index.html', msg: @msg.val(), =>

# Initialise
jQuery ->
  form = new ContactForm

You can also use your view models on elements already in the DOM like so:

# Or use on an existing element
jQuery -> new ContactForm(el: $('#contact'))

For completion here is the same again in JavaScript:

// Let's describe a contact form
! function ($) {
  "use strict";

  var ContactForm = Uniform.create_class({

    // The HTML template
    "template": function (built) {
          + " <textarea></textarea>"
          + "  <button>Send</button>"
          + "</form>")

    // We cache some children to properties on this object
    "elements": function (add) {
      add('msg', 'textarea')
      add('btn', 'button')

    // We delegate the submit event to @sendResponse()
    "events": function (add) {
      // attach submit event to @el
      add('submit', function (el, e) {

    // Do the sending :)
    "sendResponse": function () {
      $.post('index.html', {msg: this.msg.val()}, $.proxy(function () {
      }, this))

  // Initialise
  $(function () {
    var form = new ContactForm



  • Can be used with CoffeeScript or JavaScript
  • Can build it's own element using a template
  • Can hook onto existing elements in the DOM instead of using a previously defined template
  • Can delegate events of child elements and directly attach events to itself
  • Can cache jQuery objects so that you don't have to
  • Can be used with AMD or simply included in your HTML

Getting a copy

You can simply use the JS found in the dist folder of the Uniform git repo


Clone the repository and then run "cake build" to make a fresh copy of Uniform.

Future developments

  • Since we have added the add() syntax for events we can now remove the need for a blank string to indicate placing the listening directly on @el. The only thing that would break is the object syntax which as of v0.5.x is deprecated and will be remove in v0.6.x. So as of v0.6.x I will:
    • remove the object syntax from events and elements
    • remove the blank string syntax to put it in line with jQuery's use of a blank string (match all elements)




Luke Morton

Something went wrong with that request. Please try again.