
Object.applyDefaults = function(obj, defaults) {
	for (var key in defaults) {
		if (obj[key] == null) {
            obj[key] = defaults[key];
        }
	}
	return obj;
};

GenericClass = {
    newWithArgs: function(classtype, args) {
        if (args._class == classtype.prototype._class) { return args; }
        return new classtype(args);
    }
};


Number.prototype.currency = function() {
    return '$'+this.toFixed(2);
};

Array.prototype.indexWhen = function(test) {
    for (var i = 0; i < this.length; i++)
        if (test(this[i])) return i;
    return -1;
};



var $val = function(thing) {
    if (typeof thing == 'function') {
        return thing();
    }
    else {
        return thing;
    }
};

