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