Created
May 10, 2012 20:57
-
-
Save hughfdjackson/2655842 to your computer and use it in GitHub Desktop.
Awfully silly interfaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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