First, the reference
Copy Code code as follows:
Produces an Array object
var items = new Array (' 1 ', ' 2 ', ' 3 ');
Causes a reference to point to the object
var itemref = items;
Items.push (' 4 ');
Items and Itemref point to the same object
Alert (Items.length = = itemref.length);
Modifying an object produces a new object
var item = ' Test ';
var itemref = Item;
item+= ' ing ';
Item and Itemref no longer point to the same object at this time
Alert (item!= itemref);
Second, to determine the number and type of incoming parameters
Copy Code code as follows:
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);
}
The decision type can use the constructor property of the TypeOf and JavaScript objects
Copy Code code as follows:
typeof can use a string to express the type name of a variable
Determines whether a variable num is a string type
if (typeof num = ' string ')
But typeof pairs are both object array types that cannot be distinguished
Use constructor to interpret 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's variable
function Strict (Types,args) {
if (types.length!= args.length) {
Throw "Invalid number of arguments";
}
for (var i=0; i<args.length; i++) {
if (Args[i].constructor!= types[i]) {
Throw ' parameter type mismatch '
}
}
}