JS Rhino Book, Learning Notes (a) __js

Source: Internet
Author: User
Tags wrapper

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.

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.