For the object-oriented javascript study notes, you can refer to a lot of convenient articles that have been updated before. I. References
The Code is as follows:
// Generate an array object
Var items = new Array ('1', '2', '3 ');
// Point a reference to this object
Var itemRef = items;
Items. push ('4 ');
// Items and itemRef point to the same object
Alert (items. length === itemRef. length );
// Modify the object to generate a new object
Var item = 'test ';
Var itemRef = item;
Item + = 'in ';
// At this time, item and itemRef no longer point to the same object
Alert (item! = ItemRef );
Ii. determine the quantity and type of input parameters
The Code is 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 constructor attributes of typeof and javascript objects can be used to determine the type.
The Code is as follows:
// Typeof can express the type name of a variable using a string
// Determine whether the variable num is of the string type
If (typeof num = 'string ')
// However, all types of typeof object array cannot be distinguished.
// Use constructor to determine whether num is of the String type
If (num. constructor = String)
If (num. constructor = Array)
// This function determines the variable length and type of a function.
Function strict (types, args ){
If (types. length! = Args. length ){
Throw "invalid parameter count ";
}
For (var I = 0; iif (args [I]. constructor! = Types [I]) {
Throw' parameter Type Mismatch'
}
}
}