Skip to content

Instantly share code, notes, and snippets.

@marshallds
Created April 5, 2013 16:59
Show Gist options
  • Save marshallds/5320879 to your computer and use it in GitHub Desktop.
Save marshallds/5320879 to your computer and use it in GitHub Desktop.
thanks to mrgenixus
(function(){ //don't work in the global scope
var double = function(a){ return a * 2; }
var process_validation = function(validation_params){
if (validation_params) return function(val){
// do magjiks
if (validation_params.filter) val = val.match(validation_params.filter)[0]
val = Math.round(val)
if (validation_params.min) val = max(val,validation_params.min)
if (validation_params.max) val = min(val,validation_params.max)
return val;
}
return function(val){
return val; //don't do any magic
}
}
var getterSetter = function(validation_params){
var _val = (validation_params && validation_params.defaultVal) || undefined;
var process = process_validation(validation_params);
return function(val){
if (typeof val == 'function'){ val = val(_val) }
val = process(val);
return _val = val || _val;
}
}
})();
function StateObject() {}
var state = new StateObject();
StateObject.prototype.width = function(){return true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment