Last active
October 23, 2019 19:47
-
-
Save henriquegogo/1f5925315a193d54bbba7f9e7ddd2fe6 to your computer and use it in GitHub Desktop.
Javascript Type Check
This file contains hidden or 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 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