Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created May 10, 2012 20:57
Show Gist options
  • Select an option

  • Save hughfdjackson/2655842 to your computer and use it in GitHub Desktop.

Select an option

Save hughfdjackson/2655842 to your computer and use it in GitHub Desktop.
Awfully silly interfaces
var interface = function(inter){
return {
test: function(testee) {
for ( var prop in inter ) {
if ( !(prop in testee) ) return false }
return true
}
}
}
var myInter = interface({ x: true, y: true, f: true })
, result1 = myInter.test({ x: 45, y: 23, f: null }) // true
, result2 = myInter.test({ x: 45, y: 23, f: undefined, foo: 'sd' }) // true
, result3 = myInter.test({ x: 45, y: 45 /* missing f */ }) // false
console.log(result1, result2, result3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment