Object-oriented javascript (notes)

Source: Internet
Author: User

I. References
Copy codeThe 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
Copy codeThe 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.
Copy codeThe 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; I <args. length; I ++ ){
If (args [I]. constructor! = Types [I]) {
Throw' parameter Type Mismatch'
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.