1. Quote
//Generate an array object
var items = new Array('1','2','3');
//Make a reference point to the object
var itemRef = items;
items.push('4');
//items and itemRef point to the same object
alert(items.length === itemRef.length);
//Modifying the object will generate a new object
var item = 'test ';
var itemRef = item;
item ='ing';
//At this time item and itemRef no longer point to the same object
alert(item != itemRef);
2. Determine the number and type of incoming parameters
//arguments can be used to determine the number of function parameters
function sendMessage(msg,obj){
if(arguments.length ==2)
obj.handleMsg(msg);
else
alert(msg);
}
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'
}
}
}