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), which inherits the method of the string and uses it to handle the reference to the property, as long as the property of the string s is referenced. Once the property reference is finished, the newly created object is destroyed (the implementation does not necessarily create the object, but the entire 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 give 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, this property does not exist naturally, So the t output value is undefined.
This code shows that when reading the property value (or method) of a number, string, or Boolean, it behaves like an object, but when an attempt is made to assign a value to its property, the action is ignored: the modification occurs only on the temporary object, and the temporary object does not persist.
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