最近我发现Google Closure Compiler这么酷.有没有其他方法可以获得编译的静态类型语言的好处?
更新
它不是关于真正的编译器,而是关于JavaScript-JavaScript转换器,它提供类型验证等,优化和压缩.
javascript compression compiler-construction optimization google-closure-compiler
在Javascript中,有没有办法检查函数参数的类型?我想编写一个名为的函数checkTypes,它执行以下操作:
function checkTypes(typeArr){
//if the types do not match typeArr, throw an error
}
function exampleUsage(arr1, arr2, num1){
checkTypes("object", "object", "number");
//throw an error if the types do not match the corresponding elements
}
Run Code Online (Sandbox Code Playgroud)