JavaScript Wrapper Object

Source: Internet
Author: User

Original: JavaScript Wrapper object

A JavaScript object is a composite value that is a collection of properties or named values, through the symbol "." To refer to a property value, which we call a method when the value of the property is a function.

We see that the string also has properties and methods:

var s= "hello,world! ";

var word=s.substring (S.indexof ("") +1,s.length);

Since the string is not an object and why it has properties, JavaScript converts the string value to an object by invoking the constructor of the new string (s), as long as the property of the string s is referenced.

This object inherits the method of the string and uses it to handle the reference to the property, and once the property reference is finished, the newly created object is destroyed (the object is not necessarily created on implementation).

Just the whole process looks like this).

As with strings, numbers and Booleans have their own methods: a temporary object is created with the number () and Boolean () constructors, and the calls to these methods are from this temporary object.

This temporary object is called a wrapper object.

Note:

var s= "test"; Declares a string

s.len=4; Set a Len property for it

var T=s.len; Query This property

At this time we should output t should be undefined, the second line of code to create a temporary string object, and its Len property is assigned a value of 4, then destroy the object, the third line of code through the original string value s

Set a new property, try to read its Len attribute, which naturally does not exist, so the T output value is undefined.

This code surface, when reading a numeric, String, Boolean property value (or method), behaves like an object, but when trying to assign a value to its property, the action is ignored: the modification occurs only on the temporary object,

This temporary object has not been kept.

A temporary object created when accessing a string, numeric, or Boolean property is called a wrapper object, and it is only occasionally used to differentiate between string values and string objects, numeric and numeric objects, Boolean values, and Boolean objects

JavaScript Wrapper Object

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.