JSFiddle - React, Tailwind, and code Playground
by tonyleeper
JavaScript
/**
contract.requires concept
*/
var contract = contract || {};
contract.requires = function(args, expectedTypes) {
for (var i = 0; i < args.length; i++) {
if (args[i] !== null && args[i] !== undefined && typeof args[i] !== expectedTypes[i]) {
throw new Error("type exception, expected {" + expectedTypes[i] + "}, but was passed {" + typeof args[i] + "}");
}
}
};
function test(a, b, c) {
contract.requires(arguments, ["string", "number", "string"]);
console.log("you made it!");
}
test("foo", 2,"sfsdf");