草庐IT

checkTypes

全部标签

javascript - 检查 Javascript 中函数参数的类型

在Javascript中,有什么方法可以检查函数参数的类型吗?我想编写一个名为checkTypes的函数来执行以下操作:functioncheckTypes(typeArr){//ifthetypesdonotmatchtypeArr,throwanerror}functionexampleUsage(arr1,arr2,num1){checkTypes("object","object","number");//throwanerrorifthetypesdonotmatchthecorrespondingelements} 最佳答案