Skip to content

Instantly share code, notes, and snippets.

@callmehiphop
Last active August 29, 2015 14:03
Show Gist options
  • Save callmehiphop/bdbf35b68460d2197424 to your computer and use it in GitHub Desktop.
Save callmehiphop/bdbf35b68460d2197424 to your computer and use it in GitHub Desktop.
the worst idea imaginable
(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