Last active
August 29, 2015 14:03
-
-
Save callmehiphop/bdbf35b68460d2197424 to your computer and use it in GitHub Desktop.
the worst idea imaginable
This file contains 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
(function () { | |
'use strict'; | |
var slice = Array.prototype.slice; | |
Function.prototype.expect = function expect () { | |
var argTypes = slice.call(arguments); | |
var functionToCall = this; | |
return function expectWrap () { | |
var args = slice.call(arguments); | |
for (var i = 0, l = argTypes.length; i !== l; i++) { | |
if (args[i].constructor !== argTypes[i]) { | |
throw new TypeError('Expected ' + argTypes[i].name + ' for ' + suffix(i) + ' argument'); | |
} | |
} | |
return functionToCall.apply(this, args); | |
}; | |
}; | |
function suffix (number) { | |
return { | |
'1': '1st', | |
'2': '2nd', | |
'3': '3rd' | |
}[++number] || number + 'th'; | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment