Skip to content

Instantly share code, notes, and snippets.

@e2thex
Created February 27, 2014 19:44
Show Gist options
  • Select an option

  • Save e2thex/9257827 to your computer and use it in GitHub Desktop.

Select an option

Save e2thex/9257827 to your computer and use it in GitHub Desktop.
Validating on object fits a implemenation
Object.prototype.NAMESPACEvalidate = function(validator) {
validator(this);
return this;
}
isValid = function(item) {
if(typeof item.coolMethod !== 'function') {
throw("not a valid item, missing coolMethod");
}
}
doFunStuffWithItems(item) {
return item.NAMESPACEvalidate(isValid).coolMethod("baseball")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment