Recently every day to take time to see the Rhino book, obviously can feel and before the time there is a difference, reading ability and experience has a great promotion, previously did not understand some of the knowledge, there are some hidden in the details of knowledge, now can be realized.
1, Packaging objects
Temporary packaging objects
The JS data type is divided into the original data type and the reference data type, and the original type contains Number,string,boolean etc.
We all know that by using literal literals to declare a variable and assign it a string, the variable does not have the object's properties and methods;
var str= ' Wangze ';
str.len=4;
Typrof (str)//string
Console.log (Str.len)//undefined
Above this chestnut, we can give the original type value to attribute, at this time JS will treat it as a wrapper object, but then JS will delete the object, so the output of its property value is undefined. We refer to this object as a temporary wrapper object.
Permanent Wrapper Object
To add a property to a string, you can only convert it to a pair, as shown in the following example:
var str=new String (' Wangze ');
str.len=4;
typeof (str)//object
Console.log (Str.len)//4
This is the permanent packaging object.
2, JS inside some of the global constants
Math and JSON are property objects of JS's global object
Number (), String (), Boolean (), Date () is the global constructor for JS (also known as global Class)
Undefined,infinity, and Nan are the global properties of JS
Parsint (), eval (), and isNaN () are the global functions of JS
How to get Global objects:
var a=this;
3, the artful use of operators
In some code, it's common to see people write this
A + ';
+a;
Go back and check it out, the first one is to convert a to a string,
The second is to convert a to a number;
A.tostring ()
Number (a)
Same
4, JS object of ToString Method and valueof method is very important. Go back today and read it tomorrow.