Type Checking JS

Run Settings
LanguageJavaScript
Language Version
Run Command
function assert (condition, errorMessage) { if (condition == false || condition == null) { throw errorMessage; } } function typecheck (argTypes, args) { var i; for (i in argTypes) { var expected = argTypes[i]; var argument = args[i]; var arg_type = typeof argument; var arg_n = parseInt(i)+1; console.log(arg_n) if (expected != "any") { if (typeof expected == "object") { var n_type; var passed = false; for (n_type in expected) { passed = arg_type == expected[n_type]? true : passed; } assert( passed, "Invalid argument #" + arg_n + ": expected "+ expected.join(" or ") +", got " + arg_type ); } else { assert( (arg_type == expected), "Invalid argument #" + arg_n + ": expected "+ expected +", got " + arg_type ); } } } } typecheck ( ["number", "any", ["string", "number"]], [1, null, {}] )
Editor Settings
Theme
Key bindings
Full width
Lines