Skip to content

Instantly share code, notes, and snippets.

@brihogan
brihogan / gist:3153178
Created July 20, 2012 20:59
A chai extension: method that'll let you test backbone model properties (in a collection) much easier than explicitly testing each property one-at-a-time.
# Create a chai helper method
chai.use (_chai, utils) ->
# Backbone collection testing of a model for particular attributes.
#
# The first key in the hash must be the index number of the model in the
# collection. The value of the index are the properties you want
# to check. Example--- 1: {title:'Root'}
#
# @param properties [hash] index#:{key:'value'}
@brihogan
brihogan / gist:2974559
Created June 22, 2012 19:08
CoffeeScript: Starter class with class, instance, and private methods
class ClassName
constructor: (attr) ->
@attr = attr
# Private
privateVariable = null
privateMethod = () ->
# Class method
@classMethod : () ->
@brihogan
brihogan / addMethod.js
Created June 22, 2012 17:28
JavaScript: Method Overloading
// Via Jone Resig: http://ejohn.org/apps/learn/#90
function addMethod(object, name, fn){
// Save a reference to the old method
var old = object[ name ];
// Overwrite the method with our new one
object[ name ] = function(){
// Check the number of incoming arguments,
// compared to our overloaded function
@brihogan
brihogan / addMethod.coffee
Created June 22, 2012 17:08
CoffeeScript: Method overloading
# Via Jone Resig: http://ejohn.org/apps/learn/#90
addMethod (object, name, fn) ->
# Save a reference to the old method
old = object[ name ]
# Overwrite the method with our new one
object[ name ] = ->
# Check the number of incoming arguments,
# compared to our overloaded function