1. Quote
2. Determine the number and type of incoming parameters
To determine the type, you can use typeof and the constructor attribute of the javascript object
//typeof can use a string to express the type name of the variable
//Judge whether a variable num is of string type
if(typeof num == 'string')
//But typeof cannot distinguish between object array types
//Use constructor to determine whether num is a String type
if(num.constructor == String)
if(num.constructor == Array)
//This function determines the length and variable type of a function variable
function strict(types,args){
if(types.length != args.length){
throw "The number of parameters is invalid";
}
for(var i=0; i
if (args[i].constructor != types[i]){
throw 'Argument type mismatch'
}
}
}