Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Last active October 23, 2019 19:47
Show Gist options
  • Save henriquegogo/1f5925315a193d54bbba7f9e7ddd2fe6 to your computer and use it in GitHub Desktop.
Save henriquegogo/1f5925315a193d54bbba7f9e7ddd2fe6 to your computer and use it in GitHub Desktop.
Javascript Type Check
function type() {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] !== arguments[++i].constructor) throw new Error('Type Error');
}
return arguments[1];
}
/*
type(
String, this.name = "Henrique",
Number, this.age = 34,
Array, this.children = []
);
var myname = type(String, "henrique");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment