JS Wrapper Object

Source: Internet
Author: User

Wrapper object: The base type has its own corresponding wrapper object: String number Boolean.

For example

var str = ' Hello ';

Str.charat (0); Here is the method of Sting type wrapper object string. When this sentence is executed, the base type finds the corresponding wrapper object type, and then wraps the object to give the base type all the properties and methods, and then the wrapper object disappears. Look at the following question .

var str = ' Hello ';

Str.number = 10;

alert (Str.number); Undefined

The result here is undefined. When executing the first sentence, STR is a basic type, when executing the second sentence, STR is an object of the wrapper object, and adds a property number to it, and then disappears.

When executing to the third sentence, STR is the object of another wrapper object, without the number attribute, so the result is undefined.

The right approach should be

var str = ' Hello ';

String.prototype.number = 10;

alert (Str.number);

JS Wrapper Object

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.