JavaScript Basic Packaging Class Introduction

Source: Internet
Author: User
Tags wrapper

To facilitate operation of the base type value, ECMAScript provides 3 special reference types:Boolean, number, and String. These types are similar to other reference types, but also have special behaviors corresponding to their respective base types. in fact, every time a primitive type value is read, the background creates an object of the corresponding basic wrapper type, which can invoke some methods to manipulate the data.

Classic Example 1:

  A string object is a primitive type, but it is also a special reference type (Basic wrapper type: an internally created object that can invoke its own internal special behavior)

1        var str = "ABCD"; 2        Str.length = 2; 3        // the output is ABCD

Above str.length = 2; the actual execution is new string ("ABCD"), then new string ("ABCD"). Length = 2, and then delete destroys the object, regardless of the previous object, so when you access Str later, or ABCD;

JavaScript Basic Packaging Class Introduction

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.